Cannot hardlink gitconfig file

I am trying to create a git repository to store all my dotfiles and config files. My idea was to simply create hard links to all the files I cared for and store those links in their own directory, which I could turn into a repository.

I hit a little, but with my ~ / .gitconfig file. It seems that whenever I run the git config command, the link I created no longer points to the correct location, for example. the file in the repository stops updating correctly.

Here's an example of using a shell and an interactive ruby ​​to determine the state associated with files.

# Create the link $ ln .gitconfig .conf_files/gitconfig # Create the link # The files are in fact linked [1] pry(main)> File.identical?('.gitconfig', '.conf_files/gitconfig') => true # Update the gitconfig file by running a 'git config' command $ git config --global alias.last 'log -1 HEAD' # The files are no longer linked. [2] pry(main)> File.identical?('.gitconfig', '.conf_files/gitconfig') => false 

I assume this is due to the way git writes the .gitconfig file. Does anyone know why this will happen, or any creative ideas to work around?

+7
source share
4 answers

Try the Eli Barzilay solution in your comment http://www.xxeo.com/archives/2010/02/16/dotfiles-in-git-finally-did-it.html :

So, I finally found a solution that takes the maximum: and put the repo in a subdirectory, and instead of symbolic links, add the configuration parameter for "core.worktree" will be your home directory. Now that you are not in your git repository in your directoryre home (so the first problem has disappeared), and you don’t have to deal with fragile symbolic links, as in the second case. You still have minor issues with excluding paths that you don't want to version (for example, "*" in the trick ".git / info / exclude"), but this is not new.

+6
source

This is completely normal, and it is actually recommended to overwrite the configuration files. Git creates a temporary file, writes the configuration, and then moves the new file over the old one. This way you will not get an incomplete configuration file (data loss) if Git is interrupted.

You can always write a script to copy or link your configuration files to your central repository.

+2
source

Check this answer, maybe it can help:

stack overflow

At the same time, do you think that you are linking in the reverse order? Create your own repository full of configuration files, etc., and then in the place where you actually use your files, create a hard link to the "real" file that is in the repository.

0
source

Thanks to Dietrich Epp's answers and tips, I decided to approach this problem from a different angle, creating a repository at the root of my file system and using .gitignore to track only those files that interest me.

My .gitignore file now looks like this:

 /* !/etc/ /etc/* # etc files !/etc/rc.conf !/etc/asound.conf !/etc/mercurial/ !/home/ !/home/matt/ /home/matt/* # Home files !/home/matt/.xinitrc !/home/matt/.gitconfig !/home/matt/.bashrc # Vim files !/home/matt/.vimrc !/home/matt/.vim/ .netrwhist 

In addition to not having to copy the files individually and store them in two different places, this has the advantage that I need. I can easily revert changes without having to manually copy files.

Thanks for helping the guys!

0
source

All Articles