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
Solution without having to change Windows HOME variable
OS: Windows 10
git version: 2.27.0.windows.1
I use portable version of Git, so all my config files are on my pen-drive(E:). This is what worked for me:
.gitconfig
and other bash files in E, so I created a folder called home where I want them all in.mkdir home
HOME="E:\git\home"
Now it no longer searches in the C:\Users<username> directory for .gitconfig but only looks in your set path above.
$ git config --global --list
fatal: unable to read config file 'E:/git/home/.gitconfig': No such file or directory
It gave an error because there isn't a .gitconfig file there yet. This is just to demonstrate that we have successfully changed the location of the .gitconfig file without changing the HOME directory in Windows.
Change HOME directory for this is wrong. Better is create symbolic link for gitconfig to HOME directory.
As someone who has been interested in this for a VERY LONG TIME. See from the manual:
$XDG_CONFIG_HOME/git/config - Second user-specific configuration file. If $XDG_CONFIG_HOME
is not set or empty, $HOME/.config/git/config will be used. Any single-valued variable set in this file will be overwritten by whatever is in ~/.gitconfig. It is a good idea not to create this file if you sometimes use older versions of Git, as support for this file was added fairly recently.
Which was only recently added. This dump is from 2.15.0.
Works for me.
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).
Look in the FILES and ENVIRONMENT section of git help config.
%PROGRAMFILES%\Git\etc
profile
HOME="c:\location_were_you_want_gitconfig"
Note: The file permissions are usually restricted, so change them accordingly or you won't be able to save your changes.