Changing .gitconfig location on Windows
By default on Windows Git places global .gitconfig in c:\documents and settings\user\
How can I change that position so .gitconfig is stored in c:\my_configuration_files\
?
Can it be done at all?
Solution 1:
If you set HOME
to c:\my_configuration_files\
, then git will locate .gitconfig there. Editing environment variables is described here. You need to set the HOME variable, then re-open any cmd.exe window. Use the "set" command to verify that HOME indeed points to the right value.
Changing HOME will, of course, also affect other applications. However, from reading git's source code, that appears to be the only way to change the location of these files without the need to adjust the command line. You should also consider Stefan's response: you can set the GIT_CONFIG variable. However, to give it the effect you desire, you need to pass the --global
flag to all git invocations (plus any local .git/config files are ignored).
Solution 2:
Change HOME directory for this is wrong. Better is create symbolic link for gitconfig to HOME directory.
- Move your .gitconfig from user home directory, to the directory where you want.
- Run command line as Administrator
- Go to your user home directory
- Enter mklink .gitconfig \PathForNewLocationOfConfig.gitconfig
Solution 3:
I have solved this problem using a slightly different approach that I have seen work for other configuration files. Git Config supports includes that allows you to point to a configuration file in another location. That alternate location is then imported and expanded in place as if it was part of .gitconfig file. So now I just have a single entry in .gitconfig:
[include]
path = c:\\path\\to\\my.config
Any updates written by Git to the .gitconfig file will not overwrite my include path. It does mean that occasionally I may need to move values from .gitconfig to my.config.
Solution 4:
Look in the FILES and ENVIRONMENT section of git help config
.