Essential Guide

Browse Sections

BACKGROUND IMAGE: deepagopi2011/stock.adobe.com

This content is part of the Essential Guide: Master Git basics and branch into DVCS
News Stay informed about the latest enterprise technology news and product updates.

Where to find system, global and local Git config files on Windows and Ubuntu Linux

 

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.

git config location

Full list of where the Git configuration files config, gitconfig and .gitconfig are located on Windows and Ubuntu Linux.

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:

  1. Worktree
  2. Local
  3. Global
  4. System
  5. Portable

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
 System  <git-install-root>\mingw64\etc\gitconfig  gitconfig
 Global  C:\Users\username\.gitconfig  .gitconfig
 Local  <git-repo>\.git\config  config
 Worktree  <git-repo>\.git\config.worktree  config.worktree
 Portable  C:\ProgramData\Git\config  config

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
 System  ~etc/gitconfig  gitconfig
 Global  ~home/<username>/.gitconfig or ~root/.gitconfig  .gitconfig
 Local  <git-repo>/.git/config  config
 Worktree  <git-repo>/.git/config.worktree  config.worktree

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" user.email=portal@example.com
file:C:/_git/mingw64/etc/gitconfig user.name=Syster Sally
file:C:/_git/mingw64/etc/gitconfig user.email=system@example.com
file:C:/Users/Owner/.gitconfig user.email=global@example.com
file:.git/config user.email=local@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.

Linux Git config files

Git config file locations on Ubuntu Linux.

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.

Where Git stores system, global and local git config files.

Figure 2. The three main locations of Windows Git configuration files.


 

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:

Join the conversation

8 comments

Send me notifications when other members comment.

Please create a username to comment.

Git's Portable Scope

Interestingly enough, I was informed that there is actually a fourth spot for configuration data on a Windows machine known is said to have 'portable Git scope.' 

%ProgramData%\Git\config

Credit for this tip goes to Badr Elmers over at SO.

Cancel
This is very interesting. Is there a way to specify portable scope using the "Git config [scope] --list --show-source" command? So far I only know of being able to set scope to:
--global
--system
--local
--worktree
--file
--blob
Cancel
I believe --file and --blob allow the Git config command to read configuration from a file or blob located outside of the standard Git config file locations. I'm not positive if file and blob are considered Git config scopes in their own right. I'll play around with it. 
Cancel
I updated the article accordingly, but I'm still at a loss for where it fits in with the cascading nature of the Git config files.
Cancel
FYI the dot in .gitconfig has nothing to do with file extensions, it is a carry over from UNIX style hidden files. In UNIX hidden files are denoted by beginning with a dot.

As a side-note file extensions aren't really a thing in UNIX systems like they are in Windows, file types tend to be derived by more reliable methods than the filename, such as a predictable sequence of bytes in a given file format).
Cancel
That is to say, neither 'gitconfig' nor '.gitconfig' has a file extension; they are both extensionless txt files, one is simply intended to be hidden to avoid cluttering up the user's $HOME directory.
Cancel
For a newbie like me, the order you explained about local, system, and global concepts are in different order in different sections which makes it hard to follow.

And have a table of columns (location, extension, cascade, ...) helps. 

Just a thought. Thanks for sharing.

Thanks for sharing.

Cancel
Table added on your suggestion!
Cancel

-ADS BY GOOGLE

SearchAppArchitecture

SearchSoftwareQuality

SearchCloudComputing

SearchSecurity

SearchAWS

Close