Change .gitconfig location on Windows

By default, Windows Git places the global .gitconfig in c:\documents and settings\user\

How can I change this position, so .gitconfig is stored in c:\my_configuration_files\ ?

Can this be done at all?

+94
git
Oct 29 '10 at 10:15
source share
11 answers

If you set HOME to c:\my_configuration_files\ , then git will find .gitconfig there. Editing environment variables is described here . You need to set the HOME variable and then open any cmd.exe window again. Use the "set" command to verify that the HOME really points to the correct value.

Changing HOME, of course, will affect other applications. However, after reading the git source code, this is the only way to change the location of these files without having to configure the command line. You should also consider Stefan's answer: you can set the variable GIT_CONFIG. However, in order to get the --global effect, you need to pass the --global flag --global all --global git (plus any local .git / config files are ignored).

+58
Oct 29 '10 at 11:18
source share

Changing the HOME directory for this is incorrect. It is better to create a symlink for the gitconfig directory in HOME.

  • Move your .gitconfig from the user's home directory to the directory in which you want.
  • Run command prompt as administrator
  • Go to user home directory
  • Type mklink.gitconfig \ PathForNewLocationOfConfig.gitconfig
+41
May 30 '11 at 4:41
source share

I solved this problem using a slightly different approach that I saw for other configuration files. Git Config supports, allowing you to point to a configuration file elsewhere. This alternate location is then imported and expanded in place, as if it were part of a .gitconfig file. So now I have only one entry in the .gitconfig file:

 [include] path = c:\\path\\to\\my.config 

Any updates written by Git in the .gitconfig file will not overwrite my include path. This means that sometimes I may need to move values ​​from .gitconfig to my.config.

+22
Jun 10 '16 at 18:51
source share

See the FILES and ENVIRONMENT section of git help config . p>

+12
Oct 29 '10 at 10:57
source share

I am not a Git master, but due to the fact that it was easiest for me to find a solution, I just selected C:\Program Files (x86)\Git\etc and opened profile in a text editor.

There is an if on line 37 # Set up USER home directory . I took out the if and placed it in the local directory that I wanted gitconfig to be, then I just copied my existing gitconfig file (located on a network drive) to this location.

+9
Aug 26 '15 at 16:00
source share

For me, changing the location of Start In (git-gui at least) didn't affect where he looked for .gitconfig. My setup at work mounts U: for our home, but we don’t have permission to write to U: directly, only the subdirectories that were created for us inside, so for me it was a violation of the transaction.

I solved the problem by making a script package that would override the HOMEDRIVE and HOMEPATH env variables for this application only. Then changed the start menu shortcut to indicate the script package instead.

+5
Jan 06 '16 at 21:16
source share

Set the HOME parameter first, then change the HOME and HOMEDRIVE to the existing directory.

 c:\git>set HOME HOME=U:\ HOMEDRIVE=U: HOMEPATH=\ 

then change HOME and HOMEDRIVE to

 set HOME=c:\tmp set HOMEDRIVE=C: 
+4
Aug 22 '17 at 13:58 on
source share

If you are on Windows and have problems changing environment or mklink variables due to insufficient privileges, a simple solution to your problem is to run the git package elsewhere.

Just right-click on git Bash.exe, click on the properties and change the "Start Logging In" property to c:\my_configuration_files\ .

+3
Aug 10 '13 at 16:10
source share

I wanted to do the same. The best I could find was @MicTech's solution. However, as @MotoWilliams points out, this does not withstand any updates made by Git in the .gitconfig file, which replaces the link with a new file containing only the new settings.

I solved this by writing the following PowerShell script and running it in my startup profile script. Each time it starts, it copies all the parameters that have been added to the .gitconfig user to the global one, and then replaces all the text in the .gitconfig file with the [include] header, which imports the global file.

I save the global .gitconfig file to the repo along with many other global scripts and tools. All I have to do is remember to check for any changes that the script attaches to my global file.

It seems to work pretty transparently for me. Hope this helps!

September 9: Updated to detect when new entries added to the configuration file are duplicated and ignored. This is useful for tools like SourceTree that will write new updates if they cannot find existing ones and do not contain include.

 function git-config-update { $localPath = "$env:USERPROFILE\.gitconfig".replace('\', "\\") $globalPath = "C:\src\github\Global\Git\gitconfig".replace('\', "\\") $redirectAutoText = "# Generated file. Do not edit!`n[include]`n path = $globalPath`n`n" $localText = get-content $localPath $diffs = (compare-object -ref $redirectAutoText.split("`n") -diff ($localText) | measure-object).count if ($diffs -eq 0) { write-output ".gitconfig unchanged." return } $skipLines = 0 $diffs = (compare-object -ref ($redirectAutoText.split("`n") | select -f 3) -diff ($localText | select -f 3) | measure-object).count if ($diffs -eq 0) { $skipLines = 4 write-warning "New settings appended to $localPath...`n " } else { write-warning "New settings found in $localPath...`n " } $localLines = (get-content $localPath | select -Skip $skipLines) -join "`n" $newSettings = $localLines.Split(@("["), [StringSplitOptions]::RemoveEmptyEntries) | where { ![String]::IsNullOrWhiteSpace($_) } | %{ "[$_".TrimEnd() } $globalLines = (get-content $globalPath) -join "`n" $globalSettings = $globalLines.Split(@("["), [StringSplitOptions]::RemoveEmptyEntries)| where { ![String]::IsNullOrWhiteSpace($_) } | %{ "[$_".TrimEnd() } $appendSettings = ($newSettings | %{ $_.Trim() } | where { !($globalSettings -contains $_.Trim()) }) if ([string]::IsNullOrWhitespace($appendSettings)) { write-output "No new settings found." } else { echo $appendSettings add-content $globalPath ("`n# Additional settings added from $env:COMPUTERNAME on " + (Get-Date -displayhint date) + "`n" + $appendSettings) } set-content $localPath $redirectAutoText -force } 
+3
Aug 27 '13 at 15:22
source share

Like someone who was interested in this VERY LONG TIME. See the manual:

$ XDG_CONFIG_HOME / git / config - The second user configuration file. If $XDG_CONFIG_HOME not installed or not installed, $ HOME / .config / git / config will be used. Any single-valued variable set in this file will be overwritten by everything in ~ / .gitconfig. It is not recommended to create this file if you sometimes use older versions of Git, since support for this file was added quite recently.

This has been recently added. This dump is from 2.15.0.

It works for me.

+2
Nov 18 '17 at 0:40
source share
  1. Go to the %PROGRAMFILES%\Git\etc folder
  2. Change file profile
  3. Add HOME="c:\location_were_you_want_gitconfig" to the first line
  4. Done

Note File permissions are usually limited, so change them accordingly, otherwise you will not be able to save the changes.

0
Jul 09 '19 at 14:04
source share



All Articles