About this article
This article was generated using an automated generation workflow utilizing generative AI. We investigated the official Git git-config and configuration precedence, and created a sample to check local and command scopes without modifying your own Git settings. Real-device execution of Git commands has not been verified.
Verification status: 📘 Official Git specification verified / Ubuntu actual device unverified
When the Git commit author name is different from what you expected, or when the user name differs for only one repositorygit config --get user.namealone does not explain the reason.
Git configurations have application scopes such as system, global, and local. When settings overlap, knowing where they are loaded from is important.git config --show-origin --show-scopeallows you to check the source along with the value.
However, actual configuration lists may contain user email addresses or internal proxies. In this case, we will observe using only a temporary Git repository without modifying actual personal settings.
Where configurations are loaded from
Typical Git configuration locations are as follows:
| Scope | Main target | Description |
|---|---|---|
| system | Entire machine | Settings shared across multiple users |
| global | All users | Default Git settings for your own use |
| local | That Git repository | Settings specific to an individual project |
| command | Execution of that command | git -cTemporarily override with these methods |
Generally, narrower scope settings take precedence over wider scope settings, but since multiple keys may be defined or multiple values may be significant, always verify the actual keys.
Official documentation is available atGit configuration reference.
Experimenting without polluting your settings
The following shell applies a configuration that ignores Git's system/global settings and creates only a temporary repository for learning purposes.
#!/usr/bin/env bash set -euo pipefail temp_dir="$(mktemp -d)" trap 'rm -rf -- "$temp_dir"' EXIT export GIT_CONFIG_NOSYSTEM=1 export GIT_CONFIG_GLOBAL=/dev/null git -C "$temp_dir" init -q git -C "$temp_dir" config --local user.name "Sample Local" echo "=== local setting ===" git -C "$temp_dir" config --show-origin --show-scope --get user.name echo "=== command-line override ===" git -C "$temp_dir" -c user.name="Sample Override" \ config --show-origin --show-scope --get user.name
mktemp -dOnly writes to the location created by.git/config. Upon completion,trapperforms cleanup. Existing repository settings are never modified arbitrarily.
Files with the same content areGitHub sample: Git configuration origin and scopesaved in.
What should be observed?
The expected result is as follows. The display format may vary depending on the execution environment and the Git version.
=== local setting === local file:/tmp/.../.git/config Sample Local === command-line override === command command line: Sample Override
Initially, the value stored in that repositorySample Localis read. In the next execution,-c user.name=...overwrites the specified value, and it should be clear that it originates from the command line.
--show-originshows which file or location the configuration value was retrieved from, and--show-scopeis an option to display the configuration scope. The scope assumes support starting from Git 2.26 or later.--show-scopeversion is assumed.
Change one place and compare
Sample OverrideRewriteSample Anotherto and re-run.
git -C "$temp_dir" -c user.name="Sample Another" \ config --show-origin --show-scope --get user.name
Even if you change the command arguments,.git/configwritten toSample Localdoes not change. In other words,settings that change only a single execution are separate from persistent repository settings.
Another verification method is to displaygit config --local --listin a temporary repository andSample Localcompare whether remains.
Configuration Priority and Troubleshooting
A common real-world scenario is when command results differ between GitHub and the local environment. For example, after checking out in GitHub Actions, a different HOME, system configuration, and Git version from your local PC are used. Do not assume that results will match between your PC and CI.
On the other hand, in CI, it is best to avoid logginggit config --listas is. Authentication helpers, usernames, proxies, internal corporate paths, and other sensitive information may sometimes be exposed.
When investigating the cause, the basic approach is tonarrow down the target keys.ing
git config --show-origin --show-scope --get user.name git config --show-origin --show-scope --get core.autocrlf
With non-existent settings, the exit code may be non-zero. Automated scripts must determine whether to treat such cases as unset or as errors. If unset values are silently treated as empty strings and execution continues, unintended default values may go unnoticed.
Additionally, because older versions of Git that do not support--show-scopewill result in an option error, be sure togit --versioncheck
Did the configuration actually change, and how deep should you check?
To troubleshoot incorrect Git configurations, verify whether you are in the target repository, which keys are being retrieved, which scope is taking effect, and whether environment variables are overriding settings from CI or an IDE.
Before manually modifying Git configuration files, it is safer touse read-only checks to understand the origin. Especially when pasting command outputs to public blogs, replace actual usernames, email addresses, and credentials with dummy values.
