Sub topic 12
Finding where a setting comes from
This chapter assumes you know the four configuration scopes (system, global, local, worktree), the basic git config read and write commands, and how includeIf works. Here you will learn to answer one question: why does this setting have this value?
How Git picks a value
Git reads the files in order: system, then global, then local, then worktree. If the same key appears more than once, the last value read wins. Files pulled in with include or includeIf are read at the position of the include line.
List everything with its source
--list prints every active setting. Adding --show-origin puts the file name in front of each line.
git config --list --show-originTypical output, shortened:
file:/etc/gitconfig core.autocrlf=input
file:/home/ada/.gitconfig user.name=Ada Lovelace
file:/home/ada/.gitconfig [email protected]
file:.git/config [email protected]:ada/demo.git
file:/home/ada/.gitconfig-work [email protected]The output follows reading order. user.email appears twice, and the later line, from .gitconfig-work, is the effective value.
Git 2.26 and later can also print the scope name. This is useful when the file path alone doesn't tell you which scope you are looking at.
git config --list --show-origin --show-scopeAsk about one key
For a single key, --get prints the value that wins. Combine it with --show-origin to see which file supplied it.
git config --show-origin --get user.emailTo see every value for a key, including the ones that were overridden, use --get-all.
git config --show-origin --get-all user.emailThe last line of that output is the effective value. If the output has only one line and it isn't what you expected, no other file sets that key.
Debug a conditional include
includeIf rules depend on where you run the command. The same global file can give different answers in different directories, so test from inside the repository in question.
git -C ~/work/payments config --show-origin --get user.email
git -C ~/play/notes config --show-origin --get user.emailThe first command should name .gitconfig-work. The second should name .gitconfig. If the first one names .gitconfig, check these common causes:
- The
includeIf "gitdir:~/work/"path needs the trailing slash to match everything below the directory. - The
[includeIf]block comes before the[user]block in the same file. The later[user]block then overrides the include. Put includes after the defaults. - The
pathin the include is relative to the file that contains it, not to your current directory. - You ran the command outside a repository.
gitdir:conditions can't match without one.
Inspect aliases
List the aliases and where they come from:
git config --show-origin --get-regexp '^alias\.'To see what Git actually runs when you type an alias, turn on tracing for one command:
GIT_TRACE=1 git lgThe trace includes a line like alias expansion: lg => log --graph --oneline --decorate --all. If an alias misbehaves, this shows whether the expansion is what you wrote.
Open the file that wins
Once you know which file holds the value, edit it directly.
git config --global --editUse --local or --system instead of --global to open the other files. Git edits the file you name, so make sure it is the same one --show-origin pointed to.
Common diagnoses
| Symptom | Likely cause | Check |
|---|---|---|
| Wrong commit email in one repository | Local config overrides the global value | `--show-origin --get-all user.email` |
| Setting has no effect | The key is misspelled, or a later file overrides it | `--list --show-origin`, then search for the key |
| Work identity not applied | `includeIf` pattern doesn't match the path | Run from inside the repository |
| Alias runs the wrong command | A later definition replaces it | `--get-regexp '^alias\.'` |
Exercise
Running git config --show-origin --get-all user.email inside a repository prints two lines. The first names /home/ada/.gitconfig with [email protected]. The second names .git/config with [email protected]. Which address will Git use for new commits, and how would you remove the unwanted one?
Show answer
Git uses [email protected], because the local file is read after the global file and the last value wins. To remove it, run git config --local --unset user.email in the repository, and the global value applies again.