Where Git Settings Live: System, Global, and Local Config Files
Git keeps its settings in three main files: a system file for every user on the machine, a global file for you, and a local file inside each repository. Each level overrides the one before it, so the local .git/config beats ~/.gitconfig, which beats the system file. This guide covers the git config system, global, and local files: where each one lives, which value wins, and how to trace any setting back to its source.
Quick answer
When you run git config, you are reading and writing plain text files. Per the Pro Git book, Git looks at three levels:
| Level | Flag | Path | Applies to | |---|---|---|---| | System | --system | [prefix]/etc/gitconfig | Every user and repository on the machine | | Global | --global | ~/.gitconfig or ~/.config/git/config | Everything you do as one user | | Local | --local | .git/config | One repository |
"Each of these levels overwrites values in the previous level," as the book puts it, "so values in .git/config trump those in [path]/etc/gitconfig." If you pass no flag when writing, Git uses the local file, and it needs you to be inside a repository.
How it actually works
The three files and their paths
The system file is shared by every account on the machine, so changing it takes administrator privileges. Most people never touch it, and on a personal machine you probably won't either.
The global file is the one you edit most. Git's reference documentation lists two possible locations: $XDG_CONFIG_HOME/git/config and ~/.gitconfig. When XDG_CONFIG_HOME is unset or empty, Git uses $HOME/.config/. If both files exist, both are read, in that order. When you write with --global, Git targets ~/.gitconfig, or the XDG file if that one exists and ~/.gitconfig does not.
The local file lives at $GIT_DIR/config, which in an ordinary repository is .git/config. It holds settings for that one project, a remote URL for example.
On Windows, Git looks for .gitconfig in your $HOME folder, usually C:\Users\<you>. For Git for Windows 2.x, the system file is at C:\ProgramData\Git\config.
There are two more scopes. A worktree file, $GIT_DIR/config.worktree, is only read when extensions.worktreeConfig is turned on. And the command scope, set with git -c key=value <command>, applies to a single command and sits above every file.
Which value wins
Git reads the files in order, from system to global to local, and "last value found" takes precedence. So if the system file sets core.editor to one thing and your global file sets another, yours wins. A key that can hold several values, such as a list, collects values from all the files instead of replacing them.
One more rule saves confusion: git config writes to only one file at a time. If a setting doesn't change after you edit it, a file with higher precedence may be overriding it.
Finding where a value comes from
You don't have to guess. Ask Git:
git config --list --show-origin
git config --show-origin user.email
git config --list --show-scopeThe first lists every setting and the file it came from. The second answers for one key. A line looks like this, from the Pro Git example:
file:/home/johndoe/.gitconfig falseThat tells you which file "had the final say." --show-scope adds the scope name instead (system, global, local, worktree, or command).
Because the files are plain text, you can also open them in any editor. The syntax is simple: a [section] header, then key = value lines. Many other tools follow the same pattern, such as your SSH config file.
When to use each level (and when to skip it)
Global is the right home for settings that follow you everywhere: user.name, user.email, core.editor, and init.defaultBranch. You set these once.
git config --global user.name "Your Name"
git config --global init.defaultBranch mainLocal is for exceptions. If one repository needs a different email address, run git config user.email "work@example.com" inside it, and that value wins there only.
System is rarely worth the trouble on a personal machine. It makes sense for a shared server or a managed workstation where an administrator wants the same defaults for everyone.
When local-versus-global is not granular enough, Git can include one file from another with include.path, or conditionally with includeIf. A common use is applying a work identity to every repository under one folder:
[includeIf "gitdir:~/work/"]
path = ~/.gitconfig-workRelative include paths are resolved relative to the file that contains the directive. Two environment variables help in special cases: GIT_CONFIG_GLOBAL and GIT_CONFIG_SYSTEM point Git at different files, and GIT_CONFIG_NOSYSTEM skips the system file.
Your global file is also a good candidate for a dotfiles repository, so your settings follow you between machines. Settings that belong to a repository's contents, such as ignore rules, live in a .gitignore file instead.
Skip hand-editing the system file unless you have a reason. If you must change it, use git config --system so you don't break the syntax.
How Carets fits in
Git's config files are plain text dotfiles, which makes them easy to read and tweak anywhere. Carets is a fast, native notes and code editor for iPhone, iPad, and Mac. It opens .gitconfig-style files as plain text, and syntax highlighting for config files keeps the sections and keys easy to scan. Files, projects, and tags let you keep your dotfiles together with the rest of your snippets and notes.
To be clear about scope: Carets edits files. It doesn't run Git for you. Use it when you want to read or tweak a config, jot down an includeIf rule, or version-control your Markdown notes with Git alongside the settings that govern them.
Download Carets on the App Store for iPhone, iPad, and Mac.
Frequently Asked Questions
Where is the global Git config file?
Usually ~/.gitconfig in your home folder. Git also reads $XDG_CONFIG_HOME/git/config, typically ~/.config/git/config. If both exist, both are read, and the later one wins.
Which wins when system, global, and local disagree?
The most specific one. Local beats global, and global beats system. A setting passed with git -c on the command line beats all the files.
How do I see which file a setting comes from?
Run git config --list --show-origin for everything, or git config --show-origin user.email for one key. Add --show-scope to see whether each value is system, global, local, worktree, or command.
Can I edit the config files by hand?
Yes. They are plain text, and Git only changes one file at a time. Hand edits are fine as long as you keep the [section] and key = value syntax intact.
Why did my command write to .git/config instead of the global file?
Without a scope flag, git config writes to the local file, which requires a repository. Add --global to write to your user file.