5 Nov

Moving your global .gitconfig file

Category:UncategorizedTag: , , :

I am using msysgit for my Git work on Windows and for quite a while I have been wanting to move the global .gitconfig file from its default location into my dropbox folder. The reason for this is probably obvious, I do not want to have to make the same configuration changes on multiple machines to get a homogenize Git environment.

So I set out to resolve this but despite numerous stops at my local Google page, I was unable to find any information on how to make Git look for the file in a different location, it always went to look for the file at %USERPROFILE%\.gitconfig.

As a last resort I asked Joshua Flanagan if he had any idea on how I could configure Git or msysgit to make this possible. Unfortunately he had no idea, but he did however suggest that I try using mklink, a command line utility available in Windows Vista and later.

mklink enables you to create either symbolic or hard links for files or directories. What I needed was a symbolic link, which simply explained is like a shortcut to a file but the difference is that the file system will resolve the symbolic link to the real file, where as a windows shortcut is a file with information in it.

To create a symbolic link for your .gitconfig file do the following

  1. Copy your .gitconfig file from the %USERPROFILE% directory, to the directory where you want to store it instead
  2. Delete the .gitconfig file in the %USERPROFILE% directory
  3. Start cmd.exe as Administrator
  4. Enter mklink .gitconfig path\to\your\.gitconfig (notice the actual filename needs to be in the second parameter or you will link to the folder it is stored in)

You should now get a message that a symbolic link was created between the two files. Try making a change in either of them and see that the change is reflected in the other one – this is because you are always editing the same file since the file system resolves the symbolic link into the real file.

3 thoughts on “Moving your global .gitconfig file

  1. In the last para, is it “You should NOT get a message…” or “You should NOW get a message…”?

Comments are closed.