This content is part of the Essential Guide: Master Git basics and branch into DVCS

Essential Guide

Browse Sections
News Stay informed about the latest enterprise technology news and product updates.

System, global and local Git config files on Windows and Linux

Git configuration file locations

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 locations

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

For example, 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 Older Git: <git-install-root>\mingw64\etc\gitconfig
Newer Git: <git-install-root>\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 on 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

How to 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 (main)
$ git config --list --show-origin
file:"C:\\ProgramData/Git/config" [email protected]
file:C:/_git/etc/gitconfig user.name=Syster Sally
file:C:/_git/etc/gitconfig [email protected]
file:C:/Users/cameron/.gitconfig [email protected]
file:.git/config [email protected]

Here is the same command run on Ubnutu where the Git user.name property is set in three separate scopes:

linux@location (main)
$ 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=Cameron

Git config finder script

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.

Take note of 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 likely requires 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 opens 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.

The three main locations of Windows Git configuration files. On newer Git installations, gitfconfig is in the <git root>\etc folder, not a subfolder of mingw32.

Editing git config

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 when you edit the Git config files. If you incorrectly edit any of these files, you might ruin your entire Linux or Windows Git configuration.

App Architecture
Software Quality
Cloud Computing
Security
SearchAWS
Close