Sub topic 6
Listing settings and finding where a value comes from
This chapter assumes you have Git installed, can use a terminal, and know what a repository and a commit are. It also assumes you have read the earlier chapters on scopes, config files and precedence. Here you will use that knowledge to see which value Git actually uses and which file supplies it.
Why inspection matters
Git reads settings from several files and merges them. When a commit shows the wrong email, the cause is almost always a value from a scope you did not expect. Reading a single file does not tell you the answer, because a later scope may override it. You need to ask Git for the merged result.
Listing every setting
Run this command to print all settings Git sees from the current directory:
git config --list --show-originEach line starts with the file that provided the value. The output looks like this:
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]Git prints the entries in the order it reads them: system, then global, then local. The same key can appear more than once, as user.email does above. The last entry wins, so Git uses [email protected] here.
Run the command inside a repository to see local settings. Outside a repository, Git lists only the system and global files.
Asking for one key
Scanning a long list is slow. To get the effective value of one key together with its file, use --get:
git config --show-origin --get user.emailFor the example above, this prints:
file:.git/config [email protected]--get returns the value Git would use. If you want every value from every scope, use --get-all instead.
Limiting output to one scope
You can restrict a query to one scope with --system, --global or --local:
git config --global --list
git config --local --listThis helps when you want to check what a single file contains. It does not show the merged result, so use it for auditing a file and not for finding the value in force.
Reading the origin column
The origin tells you where to go to fix a problem. The table lists the common forms.
| Origin shown | Meaning |
|---|---|
| `file:/etc/gitconfig` | System scope |
| `file:/home/ada/.gitconfig` | Global scope |
| `file:.git/config` | Local scope for this repository |
| `file:/home/ada/.gitconfig-work` | A file loaded by an `include` or `includeIf` |
| `command line:` | A `-c` option on the current command |
An included file appears under its own path. If you see a value from an unexpected file, look for an [include] or [includeIf] section in the global file.
Common errors
- Empty output from
--get. The key is not set in any scope. Git exits with status 1 and prints nothing. Check the spelling, because key names are case-insensitive but a typo creates a different key. - Wrong value despite a correct global file. A local file or an
includeIfis overriding it. Run the--show-origincommand from inside the repository, not from your home directory. - Seeing only some settings. You ran the command in a directory that is not a repository, or you added
--global. Remove the scope flag to see the merged view.
Exercise
You run git config --list --show-origin and see user.email twice, first from file:/home/ada/.gitconfig and then from file:.git/config. Which value does Git use for commits, and which command prints only that value with its file?
Show answer
Git uses the value from .git/config, because the local scope is read last and overrides global. The command git config --show-origin --get user.email prints that value and its file.
Exercise
How would you list only the settings stored in your global file, without any local or system values?
Show answer
Run git config --global --list.