Where is the global git config data stored?
Asked Answered
K

20

1333

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

Kine answered 22/1, 2010 at 0:34 Comment(13)
Are you using msysgit or something else?Conjugated
git config --global --edit should tell you the exact location no matter what kind of setup you have--just look at what file comes up in your editor.Hildy
git config --global --list was also useful for when it doesn't exist as it gave the location of where git is expecting it to be.Piraeus
For me, that command yields: e -w: e: command not foundSylviasylviculture
@AJP: This is exactly my problem, but how to change where it wants to save/read it from??Krebs
In the case of TortoiseGit, it seems to get it from the Environment variables... See code.google.com/p/tortoisegit/issues/detail?id=1925Krebs
Related: Where is git config coming from?.Kinghorn
On Aptana Studio 3 it is found at the following location: %AptanaStudio3Workspace%\.metadata\.plugins\com.aptana.portablegit.win32\etc\gitconfigKatheleenkatherin
Just to add to @MatrixFrog's comment, once opening git config --global --edit you'll probably end up in vim. From vim to get the full file path you can enter :echo expand(':%p') -- vim.wikia.com/wiki/Get_the_name_of_the_current_fileSecessionist
Adding to the comment by @user420667, the command is actually :echo expand('%p'), i.e. without the colon inside the call to expandCommentator
git config --list --show-origin will tell you the locationLangbehn
git doesn't automatically create the file. The file doesn't exist until git writes to it for the first time. So where is it? The fact is, it might not actually exist.Cinema
As a note, on linux strace -fefile in front of a command will show you every path it touches by name. so strace -fefile git config --global -l.Femineity
G
1664

Update 2016: with git 2.8 (March 2016), you can simply use:

git config --list --show-origin

And with Git 2.26 (Q1 2020), you can add a --show-scope option

git config --list --show-origin --show-scope

You will see which config is set where.
See "Where do the settings in my Git configuration come from?"

As Stevoisiak points out in the comments,

it will work with non-standard install locations. (i.e. Git Portable)

(like the latest PortableGit-2.14.2-64-bit.7z.exe, which can be uncompressed anywhere you want)


Original answer (2010)

From the docs:

--global

For writing options: write to global ~/.gitconfig file rather than the repository .git/config.

Since you're using Git for Windows, it may not be clear what location this corresponds to. But if you look at etc/profile (in C:\Program Files\Git), you'll see:

HOME="$HOMEDRIVE$HOMEPATH"

Meaning:

C:\Users\MyLogin

(on Windows 7)

That means the file is in C:\Users\MyLogin\.gitconfig for Git in Windows 7.

Gelatinous answered 22/1, 2010 at 5:2 Comment(13)
I was being really dumb, I didnt add the "--global" flag to the edit command! "git config --global --edit" showed the file with all my config changes, "git config --edit" was the file I kept opening and thinking, where is that editor/compare/etc config item I just set! Many thanks.Kine
Thanks. I've seen other places were it said it's at %USERPROFILE%. On my computer HOMEDRIVE and HOMEPATH are remapped to a network drive. Searches on my local drive were coming up with nothing. So this helped a lot.Adela
Really useful, I was having the same issue - if you're on a domain with a mapped home drive it will try and create the git config there. This would make a good feature request - use %HOMEDRIVE% or %USERPROFILE%Caucasus
Why is this called global, when it is only for one user? Wouldn't (for unix) /etc/gitconfig be "global" and ~/.gitconfig only be "local"..... and I guess .git/config "hyper-local" ----- Basically, I find the "global" term for this confusing, and I was wondering if there was a good reason for the nomenclature?Boarder
@PeterAjtai "global" because it is for all your repository. As opposed to "local" (only for one repo) or "system" (which is for all repo, for all users)Gelatinous
Modifying $HOME seems to only affect MSysGit when using its "Git Bash" shell. Even though the moved .gitconfig is visible in the shell, my PhpStorm client will prompt for user.name and user.email, then write them to my Users\username\ directory.Tangle
@N13 I don't use PhpStorm, but I use msysgit in cmd only, not in bash. And setting HOME does influence a git cmd session as well.Gelatinous
If your using Cygwin shell's, and Git for Windows, git looks for .gitconfig in ~/ , which is not the same if you use a batch shell. And honestly, I avoid batch shells like a plagueSpikenard
See stackoverflow.com/questions/606483/… about how HOME* variables work in Windows and how to handle problems with them.Magallanes
I do not see these files in my machine, but I beleive I am looking in the wrong places. I've been using git for windows and TortoiseGit, mostly operating from git bash, without issues for a long time.Customs
@Customs simply type git config --list --show-origin: that will list the actual files used by git config on your machine.Gelatinous
Turns out that the user-specific files like those in a .git repository were on a different drive altogether than my git install due to IT configurations where I am.Customs
I add some underlying info. Say my git is in "C:\Git\cmd\git.exe". It is in Path-variable. Using sysinternals process monitor I found that it is indeed the correct git but it is not the one that does the config writing. No writing happend with that image. Inital git spawns the actual git which is C:\Git\mingw64\bin\git.exe Now it searches for user settings in two folders: c:\users\username\.config and c:\users\username\.config\git\configHaerle
A
145

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à! :-)

Articular answered 12/7, 2013 at 15:56 Comment(2)
Running this command will also create a C:\Users\<user_name>\.gitconfig if it is missing.Ruffled
I'm running in a non-windowed mode and cannot find the location anywhereIrretrievable
D
103

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

On Windows, you can type this in Git Bash:

notepad ~/.gitconfig
Diaconicon answered 22/1, 2010 at 0:38 Comment(2)
This should be the same on windows.Roth
If you wanna get to it easily, write an alias :) Here's mine: alias gitconfig='open -a Sublime\ Text.app ~/.gitconfig'. Use whatever text-editor you want.Scarface
H
45

The paths for msysgit are:

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

Hidebound answered 22/1, 2010 at 4:19 Comment(3)
Probably better to describe this as %USERPROFILE% then the answer will work for all Windows versions, past, present, and future.Concentrated
Except I think it's actually %HOMEDRIVE%%HOMEPATH% as in other answers, which is equal to %USERPROFILE% in many cases, but some of us have IT configurations pointing it to a mapped drive instead.Protective
@Protective is correct. I'm in a corporate environment, where %HOMEDRIVE%%HOMEPATH% is mapped to a network drive. This means the gitconfig cannot be found when I'm off site, which then breaks anything that relies on the gitconfig.Pitman
D
35

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.

Drewdrewett answered 20/4, 2011 at 14:57 Comment(5)
I was scrolling through the answers about to post on the HOMEDRIVE and HOMEPATH variables, since they just caught me out while using Bower. It seems a number of utilities on Windows read from <system>:\User\<username>\.gitconfig, while the Git tool itself saves to %HOMEPATH%\.gitconfig. I had to go one step further and copy the updated config file from my H:` (our network uses the same drive letter for that) to my local user folder, only then did Git use the rules correctly when called by Bower.Acidulant
@ZaLiTHkA, In my corporate network the user's Home (H:) drive is them re-mapped back to the C:\User\ location as well, so I'd not noticed that. If you can identify which are the FOSS utilities that make the mistake then that would be useful info for helping getting round to reporting/fixing those tools. If they are internal corporate tools you are on your own ;-)Drewdrewett
Unless it's more complicated than a simple setter line, I'm not seeing HOME defined in the etc\profile script. It does still seem to act as described, but I'm unclear where HOME is being set nowadays.Protective
@Protective My part of the answer of where --glob config is written related specifically to Windows. The core Linux git writes to places such as where the XDG thingy directs (i.e. I'm aware that linux writes to other places and has other conventions, and importantly it does have a root directory while Windows has 'Drives' ;-)Drewdrewett
@PhilipOakley I was actually referring to Windows too; sorry I was unclear. Combining your answer and others, I was expecting some sort of HOME = $HOMEDRIVE$HOMEPATH (or similar) line in C:\Program Files\Git\etc\profile and that line doesn't seem to exist, but probably used to? I haven't been able to figure out exactly what is setting $HOME unless it's set by environment variable which I'd prefer not to do.Protective
C
21

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

Cinema answered 18/6, 2018 at 2:22 Comment(1)
there is a forth place called the portable config : here they mention the 4 places ; 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"Cesspool
P
15

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).

Plumb answered 8/5, 2019 at 10:11 Comment(1)
You can use this to figure out where the global .gitconfig is located - as long as your editor tells you what directory the file is located in. You can also use other switches (--system, --local, etc.) to find and edit other .gitconfig locations. P.S. -e is the same as --editLashawn
A
12

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.

Artie answered 5/10, 2011 at 9:48 Comment(0)
B
10

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.

Beetner answered 30/6, 2014 at 12:23 Comment(0)
S
9

Just completely agree with @cameron-mckenzie's answer here on this page, above about When is the global .gitconfig file created? (this clearly applies in case of every OS). Rest of his answer deals with Win7 systems.

In Win10 systems too, the .gitconfig global file would create for the very first time only when you tend to set user.name & user.email system variables via windows command-prompt.
As soon as it's set, the .gitconfig file would get created in %USERPROFILE% dir.

Below command works for Win & MacOS, both

So, let's suppose if .gitconfig file already exists. You can know its location via Command-prompt/Gitbash/Terminal by :

git config --global --list --show-origin
Shippee answered 12/2, 2022 at 8:18 Comment(0)
T
6

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.

Toritorie answered 6/5, 2013 at 16:43 Comment(0)
Y
4

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.

Yielding answered 23/6, 2015 at 22:45 Comment(1)
This is only the case when using GitHub for Windows.Necklace
P
4

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.

Polyphone answered 14/9, 2015 at 9:47 Comment(0)
C
3

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

Cesspool answered 30/10, 2018 at 21:34 Comment(0)
S
2

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

Spikenard answered 6/10, 2015 at 23:53 Comment(0)
H
2

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).

Hass answered 15/4, 2016 at 21:40 Comment(0)
S
2

.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

Situated answered 20/2, 2020 at 2:48 Comment(0)
T
1

Per https://git-scm.com/docs/git-config you can see the --global references the ~/.gitconfig file:

--global For writing options: write to global ~/.gitconfig file rather than the repository .git/config, write to $XDG_CONFIG_HOME/git/config file if this file exists and the ~/.gitconfig file doesn’t.

For reading options: read only from global ~/.gitconfig and from $XDG_CONFIG_HOME/git/config rather than from all available files.

See also FILES.

The FILES reference https://git-scm.com/docs/git-config#FILES does show reference to the ~/.gitconfig being the global configuration file:

FILES By default, git config will read configuration options from multiple files:

$(prefix)/etc/gitconfig System-wide configuration file.

$XDG_CONFIG_HOME/git/config

~/.gitconfig

User-specific configuration files. When the XDG_CONFIG_HOME environment variable is not set or empty, $HOME/.config/ is used as $XDG_CONFIG_HOME.

These are also called "global" configuration files. If both files exist, both files are read in the order given above.

Tilla answered 11/9, 2023 at 12:39 Comment(0)
D
0

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

Donalt answered 18/7, 2019 at 7:6 Comment(0)
D
-1

git help config

Files section have a detailed description.

enter image description here

Dustup answered 16/6, 2022 at 11:44 Comment(1)
Please review Why not upload images of code/errors when asking a question? (e.g., "Images should only be used to illustrate problems that can't be made clear in any other way, such as to provide screenshots of a user interface.") and take the appropriate action (it covers answers and most kind of text as well). Thanks in advance.Tanhya

© 2022 - 2024 — McMap. All rights reserved.