Settings in context

Lesson 5 of 25 · Git: records, branches, and collaboration

Git reads configuration from several locations. System settings apply broadly, global settings normally apply to a user, and local settings apply to the current repository. Worktree-specific configuration can also be enabled. For an ordinary single-valued setting, a more specific scope typically overrides a broader one. A command-line -c value takes precedence for that invocation; individual options and environment variables may also affect behavior. Configuration can contain private addresses or tokens: inspect output before sharing it.

In the disposable repository from the earlier lesson, inspect the effective source and compare it with the local entry:

git config --show-origin --show-scope --get user.name
git -c user.name='One Command' config --get user.name
git config --local --get user.name

The middle command prints One Command; the final command still prints the local name. --show-origin identifies the configuration file or other origin, while --show-scope identifies its scope. git config --list --show-origin --show-scope lists entries Git reads, including entries overridden elsewhere. An absent key produces no value and a nonzero exit status. Change global or system settings only deliberately; this course does not require doing so.

More than one value

Some keys legitimately accept multiple values. A single --get does not show the entire list. The following invented key is used only for this demonstration; Git does not interpret it as a feature:

git config --local --add lesson.topic 'maps'
git config --local --add lesson.topic 'soil'
git config --local --get-all lesson.topic
git config --local --unset-all lesson.topic
git config --local --add lesson.note 'example'
git config --local --remove-section lesson

--get-all prints both values in order. --unset-all removes all local entries for the key, not entries from other scopes. --remove-section removes every local key in the named section; never apply it to a section whose contents you need. For a single local value, git config --local --unset key.name removes it; with multiple values, inspect and use the appropriate documented selection or --unset-all. Removing a local override may reveal a value from another scope. Consult git help config for version-specific syntax and behavior.

Continue with Understanding history.