Git is used as distributed version control system for the majority of projects I work on. On Windows I use the official Git for Windows version, as well as the 'native' mingw/MSYS2 git binary when using the MSYS2 shell.

The location of the system and global gitconfig configuration files varies, depending on which environment (native Windows command, Windows shell or MSYS2 shell) you're using, and depending on which binary (Git for Windows versus native git). There's a logic to it, but it can be hard to figure out...

Git version 2 introduced a much easier method of finding where the git configuration files are stored, the --show-origin flag. This parameter tells you exactly where each of the configuration files can be found.

Retrieve the locations (and name value pairs) of all git configuration files:

git config --list --show-origin

Retrieve the location (and name value pairs) of the system git configuration file:

git config --list --system --show-origin

Retrieve the unique locations of all git configuration files:

git config --list --show-origin | awk '{print $1}' | uniq

Local

Regardless from where you use git on Windows, the repository (local) configuration always resides at the same location, in the root directory of your repository: .git\config

You can check this configuration using

git config --list --local

System

The system configuration has also a fixed path on Windows, relative to the installation directory: etc\gitconfig

  • For msysGit: %ProgramFiles(x86)%\Git\etc\gitconfig
  • For Git for Windows (64 bit): %ProgramFiles%\Git\mingw64\etc\gitconfig
  • For MSYS2-native git: [MSYS2-install-path]\etc\gitconfig

This configuration file can be read using

git config --list --system

Global

This is the tricky one. Basically, it depends on what the binary or environment considers the HOME directory.

When using the Windows command shell, batch scripts or Windows programs, HOME is %USERPROFILE% . The global config file will be read from %USERPROFILE%\.gitconfig

However, when you're using a (Bash) shell under MSYS2 or Cygwin, HOME under that shell is %HOME% . The global config file will be read from $HOME/.gitconfig

The global configuration file can be found on yet another location, for Windows programs that use their own HOME environment. Take Emacs (which uses magit) for example: When Emacs is started from a Windows command shell, it sets the HOME variable to %APPDATA% , which means that .gitconfig will reside in %APPDATA%\.gitconfig

This configuration file can be read using

git config --list --global

So to recap, the global git configuration file can be found under what that application considers to be the HOME directory, in .gitconfig .

Workflow setup: Linking the global configuration

In my workflow I symlink the various versions of the global configuration. The system configration stays independent. The file at %USERPROFILE%\.gitconfig is considered the master global file where you make all your changes.

Run this command from within a Windows command shell to create a symbolic link for the system and global file. Be careful, as this command deletes the current gitconfig file in your MSYS2 home directory, as well as the one in %APPDATA% . Moreover mklink doesn't expand variables, so you'll have to type in the expanded path yourself.

mklink /h %APPDATA%\.gitconfig %USERPROFILE%\.gitconfig
mklink /h [MSYS2-install-path]\home\[username]\.gitconfig
%USERPROFILE%\.gitconfig

You also might be interested in other git-related articles articles, for instance on how to diff binary files with git.

Changelog

  • 2018-04-19: Added better explanation about HOME directory, links
  • 2017-10-19: Formatting
  • 2017-09-17: Formatting
  • 2016-12-03: Added new --show-location option, changed git binary, edits.

Comments

comments powered by Disqus