日本語

Finding Which File a Git Config Setting Is Written In

​​Git​command line

git config --show-origin shows which config file each Git setting in effect is written in. Use it when git pull or commit authorship does not behave as you expect, and you need to find the file behind a setting that "should be in effect but isn't" or "is in effect but I don't remember setting". Adding --get-all also lists overridden values that are hidden, along with the file each one is written in.

Note

I tested on Ubuntu 24.04 with Git 2.43.0. I used example values for the name and email (Neko <neko@example.com>). For the home folder, I prepared an empty /home/user. For the system-wide config file /etc/gitconfig, I used a file that contained only pull.rebase = false and core.autocrlf = input. I did not test how this looks on Windows or macOS, or the config files that come with Git for Windows.

Listing all settings with the file they come from

In the test, I put a name, an email, and pull.rebase = true in the global config (--global), then created a repository called cat-tools. Running git config --list --show-origin inside it prints one setting per line, each with the file it is written in and its value.

console
$ git config --list --show-origin
file:/etc/gitconfig	pull.rebase=false
file:/etc/gitconfig	core.autocrlf=input
file:/home/user/.gitconfig	user.name=Neko
file:/home/user/.gitconfig	user.email=neko@example.com
file:/home/user/.gitconfig	init.defaultbranch=main
file:/home/user/.gitconfig	pull.rebase=true
file:.git/config	core.repositoryformatversion=0
file:.git/config	core.filemode=true
file:.git/config	core.bare=false
file:.git/config	core.logallrefupdates=true

The text after file: on each line is the file that setting is written in. /etc/gitconfig is the system-wide config, /home/user/.gitconfig is the user config (the global config), and .git/config is the config for this repository. The repository config was shown with the relative path .git/config.

Adding --show-scope also shows the kind of setting (system, global, or local) before the file name. I also used --show-scope in the article on setting a different Git name and email for each repository.

console
$ git config --list --show-origin --show-scope
system	file:/etc/gitconfig	pull.rebase=false
system	file:/etc/gitconfig	core.autocrlf=input
global	file:/home/user/.gitconfig	user.name=Neko
global	file:/home/user/.gitconfig	user.email=neko@example.com
global	file:/home/user/.gitconfig	init.defaultbranch=main
global	file:/home/user/.gitconfig	pull.rebase=true
local	file:.git/config	core.repositoryformatversion=0
local	file:.git/config	core.filemode=true
local	file:.git/config	core.bare=false
local	file:.git/config	core.logallrefupdates=true

According to the git config reference, --show-origin adds the source type (file, standard input, blob, or command line) and the actual source (such as a file path) to the output. --show-scope adds the scope of the value (worktree, local, global, system, or command).

Checking which file a single setting comes from

In the --list output, pull.rebase is written in two places: /etc/gitconfig and ~/.gitconfig. To see which one is actually in effect, specify the setting name together with --show-origin.

console
$ git config pull.rebase
true

$ git config --show-origin pull.rebase
file:/home/user/.gitconfig	true

The value in effect was true from ~/.gitconfig. Adding --get-all lists every value for the same name, in the order they were read.

console
$ git config --show-origin --get-all pull.rebase
file:/etc/gitconfig	false
file:/home/user/.gitconfig	true

The FILES section of the reference says Git reads the system-wide config, then the global config, then the repository config, and a value read later takes precedence. In the --get-all output, the value at the bottom is the one in effect.

After adding a repository setting

Inside cat-tools, I set pull.rebase to false without --global. After that change, running the same commands showed that the value in effect now came from .git/config.

console
$ git config pull.rebase false

$ git config pull.rebase
false

$ git config --show-origin pull.rebase
file:.git/config	false

$ git config --show-origin --get-all pull.rebase
file:/etc/gitconfig	false
file:/home/user/.gitconfig	true
file:.git/config	false

The true in ~/.gitconfig was not removed. It is overridden by the value in .git/config, which is read later. When I ran the same command from outside the repository (in the home folder), .git/config was not read and only two lines were shown.

console
$ git config --show-origin --get-all pull.rebase
file:/etc/gitconfig	false
file:/home/user/.gitconfig	true

Settings from another included file also show that file's name

When ~/.gitconfig loads another file with [include], the setting is not in ~/.gitconfig itself. In the test, I wrote aliases to ~/.gitconfig-alias in the home folder and loaded that file from the global config.

console
$ printf "[alias]\n\tst = status --short\n\tlg = log --oneline\n" > .gitconfig-alias && git config --global include.path "~/.gitconfig-alias"

$ cat .gitconfig
[user]
	name = Neko
	email = neko@example.com
[init]
	defaultBranch = main
[pull]
	rebase = true
[include]
	path = ~/.gitconfig-alias

With --show-origin, the aliases appeared under the name of the file that was loaded.

console
$ git config --show-origin --get-regexp "^alias\."
file:/home/user/.gitconfig-alias	alias.st status --short
file:/home/user/.gitconfig-alias	alias.lg log --oneline

--show-scope alone only tells you that this value is global. Using both options also shows which file within the global config it is written in.

console
$ git config --show-origin --show-scope alias.st
global	file:/home/user/.gitconfig-alias	status --short

The path in [include] appears as the setting include.path in ~/.gitconfig. If you also search for include, you can check together which file loads which file.

console
$ git config --show-origin --get-regexp "^(alias|include)\."
file:/home/user/.gitconfig	include.path ~/.gitconfig-alias
file:/home/user/.gitconfig-alias	alias.st status --short
file:/home/user/.gitconfig-alias	alias.lg log --oneline

Besides ~/.gitconfig, the global config can also be ~/.config/git/config (FILES section of the reference). I wrote core.editor = vim to ~/.config/git/config and core.editor = nano to ~/.gitconfig. Both are global, and the file names told them apart. The nano in ~/.gitconfig is used because it is read later.

console
$ git config --show-origin --show-scope --get-all core.editor
global	file:/home/user/.config/git/config	vim
global	file:/home/user/.gitconfig	nano

$ git config core.editor
nano

Values with no file show as "command line:"

A setting passed with git -c appears as command line:, not as a file.

console
$ git -c pull.rebase=merges config --show-origin pull.rebase
command line:	merges

Settings passed with the environment variables GIT_CONFIG_COUNT, GIT_CONFIG_KEY_<n>, and GIT_CONFIG_VALUE_<n> also appear as command line:, and their scope is command.

console
$ GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pull.rebase GIT_CONFIG_VALUE_0=merges git config --show-origin --show-scope --get-all pull.rebase
system	file:/etc/gitconfig	false
global	file:/home/user/.gitconfig	true
local	file:.git/config	false
command	command line:	merges

According to the ENVIRONMENT section of the reference, settings passed through these environment variables take precedence over values in config files, and values passed with git -c take precedence over those. When a value is in effect but you cannot find it in any config file, look for a command line: line. Also check whether environment variables such as GIT_CONFIG_COUNT are set, and whether an alias or script uses git -c.

Diagram showing pull.rebase being read in the order: system config, global config, repository config, and command line, with the final merges value being used
The order in which config files are read, and the value in effect

Removing the setting from the file you found

Once you know which file a value comes from, you can remove it by specifying that file with --file. According to the reference, --file writes to that file when setting a value and reads only that file. Here I removed pull.rebase from ~/.gitconfig.

console
$ git config --file ~/.gitconfig --unset pull.rebase

$ git config --show-origin --get-all pull.rebase
file:/etc/gitconfig	false
file:.git/config	false

Next I removed pull.rebase from .git/config as well. Only the system-wide setting remained, and that value took effect.

console
$ git config --file .git/config --unset pull.rebase

$ git config --show-origin --get-all pull.rebase
file:/etc/gitconfig	false

$ git config pull.rebase
false
Warning

If you run git config --unset without --file or --global, only the repository's .git/config is changed. As the reference states, a single git config command changes only one file. For values in the global config or in included files, use --show-origin to find the file, then specify it with --file to remove the value.

When I specified a name that is not written in any file, nothing was displayed.

console
$ git config --show-origin no.such

The exit code in this case was 1. The reference also says that git config returns exit code 1 when the name is not found. If nothing is printed, either the name is misspelled or the setting does not exist anywhere.

​Posted by 86