[git] Where does git config --global get written to?

When using git config --global to set things up, to which file will it write?

Example:

git config --global core.editor "blah"

I can't find it at these places:

C:\Program Files\Git\etc\gitconfig

C:\myapp\.git\config

I have not set an ENV?

My Git version: 1.6.5.1.1367.gcd48 – on Windows 7

This question is related to git config

The answer is


I had installed my Git in: C:\Users\_myuserfolder_\AppData\Local\Programs\Git


I think it is important to post this quote:

Git for Windows supports four levels of configuration. At the lowest level is the machine specific configuration settings known as "portable" and lives a "%ProgramData%\Git\config". One priority level us the installation specific configuration settings known as "system", which live at "\mingw64\etc\gitconfig". Both of these configuration file, generally require elevated privileges to modify.

Starting with the use specific values known as "global" configuration, which can be found at "%UserProfile%.gitconfig", we find the "user editable" configuration files. The highest priority configuration settings are in the "local" configuration, which can usually be found at ".git\config".

It see the recommendation in the blog linked is to modify the "system" or "installation" specific configuration settings, which is fine but users should expect that other installations of Git would not absorb said settings. If you want machine wide settings, use the "portable" configuration file, otherwise choose the "global" or "local" configuration files.

Hopefully, people find this information useful.

source


On *nixes, it's in ~/.gitconfig. Is there a corresponding file in your home?

On Windows you can type in git bash

notepad ~/.gitconfig

Uninstall Msysgit and install Cygwin + Git. Then global '.gitconfig' will be here: C:\cygwin(64)\home\[userName]\.gitconfig .

Now you don't have to worry about an environment variable which may be used by other programs. For example, my environment variable pointed me to a mapped drive in my work windows domain environment. I dont want my global .gitconfig sitting on my "home" mapped drive. I also don't know what might happen to other applications that might rely on that windows environment variable. Operations division might need that environment variable set to the mapped drive for a reason.

Also you don't have to worry about Mysysgit overwriting your 'profile' configuration settings if you specify a specific path to global '.gitconfig', using this method.

In general, save yourself and use cygwin bash shell in windows and be happier


I had also a problem with my global .gitconfig This is for the case someone also has this strange

git said:

fatal: unknown error occured while reading the configuration files

Now I fixed it. The problem was a second .gitconfig in this folder:

c:\Users\myUser.config\git\config

I don't know where it came from... But now everything works like a charme again.


.gitconfig file location

macOS testing OK

global

# global config
$ cd ~/.gitconfig

# view global config
$ git config --global -l

local

# local config
$ cd .git/config

# view local config
$ git config -l


maybe a bonus for you:Vim or VSCode for edit git config


# open config with Vim

# global config
$ vim ~/.gitconfig

# local config
$ vim .git/config


# open config with VSCode

# global config
$ code ~/.gitconfig

# local config
$ code .git/config


If you are using TortoiseGit on a windows PC you can use:

Settings / Git / Config / Edit global .gitconfig

to open the global .gitignore file.

But if you use your Windows (7) PC in a domain your profile dir is may be a network share (mounted as a drive). In this case TortoiseGit (at least:1.6.5.0) is pointing you to the wrong dir (on c:...). See the closed TortoiseGit issue 922 for more information. Or using %HOMEDRIVE%%HOMEPATH% to open the dir that contains the .gitignore file.


As @MatrixFrog pointed out in their comment, if the goal is to edit the config, you might want to run:

git config --global --edit

This command will open the config file (in this case, the --global one) in the editor of choice, and await for the file to be closed (just like during git rebase -i).


I was also looking for the global .gitconfig on my Windows machine and found this neat trick using git.

Do a: git config --global -e and then, if you are lucky, you will get a text editor loaded with your global .gitconfig file. Simply lookup the folder from there (or try a save as...), et voilà! :-)


I am using SmartGit with msysgit on Windows 8.1 and noticed that there can be three different locations for the gitconfig file:

%USERPROFILE%\.gitconfig
C:\Program Files (x86)\Git\etc\gitconfig
C:\Program Files (x86)\SmartGitHg\git\etc\gitconfig

But the one that is used is the one from %USERPROFILE%\.gitconfig.


I had a similar issue; the problem was that the .gitconfig file was located in

C:\Users\MyLogin\.gitconfig\

(on Windows 7)

In other words, the file was located in C:\Users\MyLogin\.gitconfig\.gitconfig, instead of on C:\Users\MyLogin\.gitconfig (which is where Git was looking for the files).


The paths for msysgit are:

Windows XP -C:\Documents and Settings\<user_name>\.gitconfig

Windows Vista+ C:\Users\<user_name>\.gitconfig


I am running Windows 7 and using git as setup by following the instructions on GitHub (a year or two back). A rather common use-case I would have thought. None of the answers above helped me, and after much frustration I eventually found my 'real' gitconfig file in the following directory;

C:\Users\Bill\AppData\Local\GitHub\PortableGit_054f2e797ebafd44a30203088cd 3d58663c627ef\etc

Obviously substitute your user name and presumably the suffix after PortableGit_ is a unique GUID or similar.


It might be useful to note (for *nix platforms): some types of global git configuration/information are stored in /usr/share/git-core/, such as git autocompletion scripts and the following (default) hooks:

  • applypatch-msg
  • post-update
  • pre-commit
  • prepare-commit-msg
  • commit-msg
  • pre-applypatch
  • pre-rebase
  • update

Each of these can contain their own set of commands to execute, at the time described by their respective filenames.


The global location is derived, on Windows MsysGit, using the HOMEDRIVE and HOMEPATH environment variables, unless you have defined a HOME environment variable. The is detailed in the 'profile' script.

In my corporate environment the HOMEDRIVE is H:, which is then mapped to a network URL \\share\$. The whole lot is then mapped to be "My Documents", which isn't where others would expect. There may have been some further problems with the drive to URL remapping. I don't even get to adjust the HOMEDRIVE or HOMEPATH variables anyway.

In my case I have defined a personal HOME environment variable and pointed it to D:\git\GitHOME and copied all those GIT files (which are without and extension) to the GitHOME directory for safe keeping.

The windows environment variables can be set via the Advanced tab in the My Computer properties dialog.


When is the global .gitconfig file created?

First off, git doesn't automatically create the global config file (.gitconfig) during its installation. The file is not created until it is written to for the first time. If you have never set a system variable, it will not be on your file system. I'm guessing that might be the source of the problem.

One way to ask Git to create it is to request an edit. Doing so will force the file's creation.

git config --global --edit

If you monitor the user's home folder when you issue this command, you will see the .gitconfig file magically appear.

Where is git configuration stored?

Here's a quick rundown of the the name and location of the configuration files associated with the three Git scopes, namely system, global and local:

  • System Git configuration: File named gitconfig located in -git-install-location-/ming<32>/etc
  • Global Git configuraiton: File named .gitconfig located in the user's home folder (C:\Users\git user)
  • Local Git configuration: File named config in the .git folder of the local repo

Of course, seeing is believing, so here's an image showing each file and each location. I pulled the image from an article I wrote on the topic.

Windows Git configuration file locations (TheServerSide.com)

Location of Git configuration files