One of the five basic Git commands beginners need to learn is git config, if for no other reason than to perform an initial commit without the Git tool pestering for a user.name and user.email address. But the git config command commonly used to initialize these fields typically employs a global switch, which gets users wondering about Git’s competing local and system scopes.
That then leads to the question about where all of these variously scoped Linux and Windows git configuration files can be found. Here we will answer all of those questions about Git config file locations and where the various gitconfig files are stored.
System, global and local Git config files
Listed in descending order of specificity, Git provides four standard scopes for storing configuration data, plus a portable scope on Windows:
Note: You will notice a ‘portable scope’ mentioned in the Windows Git config table above. This scope was pointed out to me by a reader after this article first published. The portable scope is the most general and is overridden by all other scopes.
The scopes are cascading with the most specific file taking precedence over the most general. Local scope overrides global scope. Global scope overrides system scope.
If you set up multiple Git worktrees on the same computer, you can also use the Git worktree scope, although doing so requires this scope to be enabled. Worktree scope is the most specific and will override local.
Names of Unix and Windows Git config files
Just to make life a bit more complicated, the variously scoped Git configuration files all have different names:
- gitconfig – the extensionless system Git config file
- .gitconfig – the global Git config file has no name, but is instead just an extension
- config – the local Git configuration file is simply named config, and like the system Git config file, has no extension
- config.worktree – the Git worktree configuration file flaunts both a name and an extension
Where are Windows Git config files located?
Here is where you will find Git configuration files on Windows:
|Location of Windows Git Config Files|
|Scope||Location and Filename||Filename Only|
Where are Git config files for Ubuntu Linux located?
As for the location of the Linux Git configuration files, here is where you’ll find them on Ubuntu:
|Ubuntu Linux Git Config File Locations|
|Scope||Location and Filename||Filename Only|
|Global||~home/<username>/.gitconfig or ~root/.gitconfig||.gitconfig|
Find Git config files on your own
To find the Git config file setting a given variable to a particular value, the –list and –show-origin switches of the git command can be useful. In the following example you can see the command indicating that the user.email property is set in the portable, system, local and global scopes. It also states exactly where those files Git config files are located.
Here is the git config command with list and show-origin swtiches run on Windows:
windows@location (master) $ git config --list --show-origin file:"C:\\ProgramData/Git/config" firstname.lastname@example.org file:C:/_git/mingw64/etc/gitconfig user.name=Syster Sally file:C:/_git/mingw64/etc/gitconfig email@example.com file:C:/Users/Owner/.gitconfig firstname.lastname@example.org file:.git/config email@example.com
Here is the same command run on Ubnutu where the Git user.name property is set in three separate scopes:
linux@location (master) $ git config --list --show-origin file: /etc/gitconfig user.name=Syster Sally file: /home/gme/.gitconfig user.name=Glow Ball file: .git/config user.name=Low Cal
On StackOverflow, the following command was suggested to help developers find the location of the Git config files:
sudo git -c core.editor=ls\ -al config --system --edit
The animated GIF below, pulled from 1998 when such things were cool, shows the above command being run on Ubuntu 20. Note how the command above lists the home directory as the location for the global Git config file, but when the sudo command is used below the global Git config file is in ~root.
Can’t find the global git config file .gitconfig?
Sometimes users go looking for the global and system Git config files and can’t find them. If you can’t find gitconfig or .gitconfig, it’s probably because it’s not there.
Git doesn’t actually create the gitconfig or .gitconfig files until they are referenced for the first time. Just asking Git to edit the file will force its creation, but until that happens, efforts to find the .gitconfig or gitconfig file will be fruitless.
The following operation will likely require sudo rights on a Linux distribution as you may be creating files in privileged \etc or \root directories. But when run with elevated permissions, these commands are sufficient enough to force the creation of global and system gitconfig and .gitconfig files:
/c/ global/windows git config files (master) $ sudo git config --edit --global $ sudo git config --edit --system
Each of these Git commands will open the corresponding Windows or Linux Git config file in the configuration specified editor. You may edit the file if you please, or simply close the editor immediately to force config file creation.
On the topic of editors, if you’d like to switch the Git editor to Notepad++, just issue the following command:
$ git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"
Always be careful editing the Git config files, because if you incorrectly edit any of these files, you just might ruin your entire Linux or Windows Git configuration.
Become a Git power user
Want to become a powerful Git user? Then take a look at the following Git articles and tutorials:
- How to do a Git clean up of branches and commits
- Learn to rebase onto master and rebase from the master branch
- Squash all Git commits on a branch down to one
- Shelve your changes with Git stash pop and apply
- Easily explain the Git vs GitHub difference
- Add a shallow git clone of depth 1 do your Jenkins jobs
- Set up a local Git server with a bare Git repo