Where is the global git config data stored?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
The global Git config file is stored at ~/.gitconfig on macOS and Linux, and at C:\Users\<USERNAME>\.gitconfig on Windows. This file holds user-level settings like your name, email, and preferred editor that apply to every repository you work with on that machine.
Git's Three Configuration Levels
Git reads configuration from three locations, each with a different scope. Settings at a narrower scope override broader ones:
| Level | Flag | File Location | Scope |
| System | --system | /etc/gitconfig (Linux/macOS) or C:\Program Files\Git\etc\gitconfig (Windows) | All users on the machine |
| Global | --global | ~/.gitconfig or ~/.config/git/config | All repos for the current user |
| Local | --local | .git/config inside each repo | Single repository only |
When Git resolves a setting, it reads all three files and applies them in order: system, then global, then local. A local setting always wins over global, and global always wins over system.
Finding Your Global Config File
The fastest way to locate your global config file is to ask Git directly:
This prints every global setting along with the exact file path it comes from:
If you want just the file path without the settings:
Platform-Specific Locations
macOS and Linux:
Git checks ~/.gitconfig first. If it does not exist, Git falls back to ~/.config/git/config. If both exist, ~/.gitconfig takes priority.
Windows:
Git for Windows determines the home directory from the HOME environment variable first, then falls back to HOMEDRIVE + HOMEPATH, then USERPROFILE.
Reading and Writing Global Config
Viewing all global settings
Setting common values
Removing a setting
Editing the file directly
This opens the global config file in your configured editor (or vi by default).
Inside the Global Config File
The .gitconfig file uses INI-style syntax with sections, keys, and values:
You can edit this file manually with any text editor. Comments start with # or ;.
Conditional Includes
Git 2.13 introduced conditional includes, allowing you to load different config files based on the repository path. This is useful for separating work and personal identities:
Any repository cloned under ~/work/ automatically picks up the work email without manual per-repo configuration.
Debugging Configuration Precedence
When a setting behaves unexpectedly, check where Git is reading it from:
Example output:
The --show-scope flag (Git 2.26+) adds the level label, making it clear which file is winning.
Backing Up and Syncing Config Across Machines
Many developers version-control their dotfiles, including .gitconfig. A common pattern:
On a new machine, clone the repo and recreate the symlinks. Tools like GNU Stow or chezmoi automate this process.
Common Pitfalls
Editing the wrong file. On systems with both ~/.gitconfig and ~/.config/git/config, manual edits to the XDG file are ignored if ~/.gitconfig exists. Always use git config --global --edit to ensure you are editing the right file.
Forgetting to set identity before the first commit. Git refuses to commit without user.name and user.email. Set these in global config immediately after installing Git to avoid the error on every new repository.
Using global settings that should be local. Settings like core.autocrlf or core.eol may need different values per project (especially in mixed Windows/macOS teams). Set these at the local level rather than global to avoid cross-project conflicts.
Conditional includes not matching. The gitdir pattern in includeIf must end with / to match directories correctly. Without the trailing slash, the condition may silently fail to match.
SSH key confusion with multiple accounts. Global config sets one user.email, but if you push to repos owned by different GitHub accounts, you need per-repo local config or SSH config with Host aliases to route to the correct key.
Summary
The global Git config lives at ~/.gitconfig (or ~/.config/git/config on XDG-compliant setups) and holds settings that apply across all repositories for your user account. Use git config --global commands to read and write settings, --show-origin to debug where values come from, and conditional includes to manage multiple identities. The global level sits between system-wide and per-repository config in Git's precedence chain, making it the right place for personal defaults like your name, email, editor, and aliases.
Related reading
- Where is the global Git configuration data stored?
- Where is the source to embedding-projector-standalone?
- Where to store my Git personal access token?
- Which characters are illegal within a branch name?
- Which commit has this blob?
- Why am I getting the message, fatal This operation must be run in a work tree?
- Why are connections to GitHub over SSH throwing an error Warning Remote Host Identification Has Changed?
- Why can't a branch name contain the 'space' char?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.