Git Config Scopes and Precedence
Find the effective value
A Git setting is a key and value, not a tracked project file. A scalar setting such as core.editor may appear in several scopes: system, global (user), local (repository), optional worktree, then command. Normally the last applicable value wins; some keys accumulate multiple values, and some are restricted to protected scopes. A local setting is not sent by push. In our disposable lab, demo.theme is an invented harmless key, not a Git feature. Predict the effective value before querying it.
git config --show-origin --show-scope --get-all demo.themegit config --get demo.themegit -c demo.theme=command config --get demo.themeIsolate the configuration
The lab redirects system and global files to temporary paths. Never modify the real system or user config for practice. Set local values only in the fixture; the -c option affects that invocation and subprocesses inheriting the setting, not the stored local value. Environment pairs GIT_CONFIG_COUNT, GIT_CONFIG_KEY_0 and GIT_CONFIG_VALUE_0 are command-scope entries, overridden by an explicit -c. An include can insert additional settings; inspect origin rather than assuming one file per scope. Avoid dumping real configuration because URLs and helper settings may expose secrets.
git config --local demo.theme localgit -c demo.theme=command config --get demo.themegit config --local --get demo.themeWorktree settings and multiple values
By default linked worktrees share repository configuration. Enable extensions.worktreeConfig in the disposable repository before using --worktree for distinct values. Then one worktree can override the local setting without changing the other. Without the extension --worktree behaves like --local. A repeated key is not always scalar: inspect all entries with --get-all, and consult the key-specific semantics. Protected settings such as safe.directory cannot be made effective by putting them in a repository config. Do not bypass ownership checks.
git config --worktree --get demo.themegit config --get-all demo.listPractice
The fixture has system=system, global=global, local=local and worktree=worktree. What is effective with and without -c demo.theme=command? What changes on disk after the command exits? Confirm scope and origin. Explain why a team should commit shared policies as reviewed project files rather than assume local config propagates.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Git Config Scopes and Precedence — knowledge check
Reason about configuration, platform behavior and execution boundaries.
Which scope normally wins over local for a scalar setting?
Which command shows all values and their origins?
What happens to local config after git -c demo.theme=command config --get demo.theme?
What enables separate worktree configuration?
Why is last value wins not universal?