One of the five basic Git commands beginners need to learn is git config, if for no other reason than the need to be able to perform a commit without the Git tool pestering them for a username and email address.
But the required git config command that sets up a username and email address typically employs a –global switch, which tends to get Git beginners to start pondering about alternate scopes and asking questions about where all of these Windows git configuration files are saved.
System, global and local Git config files
Git provides three different scopes for storing configuration data. Accordingly, when using the git config command, one of these three scopes can be specified:
The scopes are cascading, so system scope trumps global scope and local scope trumps global scope.
Names of Windows Git config files
Just to make life a bit more complicated, the Git configuration files all have different names. Furthermore, Windows Git config files are each stored in different locations.
- The extensionless system Git config file is named gitconfig.
- The global Git config file has no name, but is instead just an extension. The global Windows Git config file is named .gitconfig.
- The local Windows Git configuration file is simply named config, and like the system Git config file, it has no extension.
Where are Git config files stored?
As for the location of these three Windows Git configuration files, here is where you’ll find them:
- The system Git config file is found in the mingw32\etc folder of the Git installation
- The global Git configuration file is found in the root of the user’s local profile or home directory (C:\Users\git-user\)
- The local Git config file is stored inside the .git directory of the repository in which you are working
Can’t find the global git config file .gitconfig?
It should be stated that sometimes users go looking for the global git config file, .gitconfig, and can’t find it. That’s because Git doesn’t actually create it until it’s used for the first time. Even just asking git to edit the file will force its creation, but until that happens, efforts to find the .gitconfig file will be fruitless.
A quick command to force the creation of the .gitconfig file follows:
/c/ global/windows git config files (master) $ git config --edit --global
Editing Windows Git config files
If you are interested in viewing or editing Git config files, simply use the git config command, specify the scope and add an –edit switch.
/c/ windows git config (tutorial) $ git config --global --edit $ git config --system --edit $ git config --local --edit
Each of these Git commands will open the corresponding Windows Git config file in the configuration specified editor. Just be careful, because if you incorrectly edit any of these files, you just might ruin your entire Windows Git config.