Configuration Levels

The Three Levels of Git Configuration

Git 1,932 reads configuration from three files, in order, and a later value overrides an earlier one:

Where Git reads its configuration, from lowest to highest priority
Scope File Option Applies to
system /etc/gitconfig, or etc\gitconfig under Git for Windows 47,417 --system Every user
global ~/.gitconfig or ~/.config/git/config --global You, in every repository
local .git/config --local (the default) One repository

Two more scopes sit on top: worktree (.git/config.worktree, when extensions.worktreeConfig is on) and command, a -c key=value on one command line. --show-scope and --show-origin say where each value came from:

Counting settings per scope and finding the file behind a valueShell
echo "$GIT_CONFIG_GLOBAL"
git config list --show-scope | cut -f1 | uniq -c
git config get --all --show-origin filter.lfs.required
git -c core.editor=vim config get --show-scope core.editor
Output
/home/dev/v5-ch2/gitconfig
      4 system
     10 global
     25 local
file:/etc/gitconfig     true
file:/home/dev/v5-ch2/gitconfig true
command vim

This chapter's global file is not ~/.gitconfig: the GIT_CONFIG_GLOBAL environment variable (Git 2.32) points Git at another file, keeping the book's examples apart from other Git setups on the machine; GIT_CONFIG_NOSYSTEM=1 skips the system file. filter.lfs.required exists twice, once from Ubuntu 225 's git-lfs 127,865 package and once from git lfs install (Git LFS); --all lists both, and plain get returns the last.