If you want to blame Git for weird behavior you noticed this morning you should first know where it reads its settings. Git has three levels of configuration that stack and fight for dominance. This guide shows where those files live on Ubuntu and Windows and how to inspect and change them without causing your dotfiles to mutiny.
Quick map of git configuration levels
Git reads settings from three places in this order from weakest to strongest. Think of it as a family feud where the repo wins.
- System config applies to every user on the machine and provides defaults for all repos. This is system config.
- Global config applies to one user account and is usually where you store name, email and general preferences. This is global config and often lives with your dotfiles.
- Local repo config is inside a single repository and overrides the other two. Use this for repo specific remotes and hooks.
Where to look on Ubuntu
System config file path is /etc/gitconfig
. The per user file is ~/.gitconfig
. Repository specific settings live in .git/config
inside the repository root. Yes that file will win arguments with your global config every time.
Where to look on Windows
On Windows system config often lives in the Program data area used by the installer. A common path is %PROGRAMDATA%/Git/config
or in the Git installation folder under Program Files. Your user level settings are in %USERPROFILE%/.gitconfig
. Repo local config is still .git/config
inside each repo.
Show exactly which file provided each setting
If you are tired of guessing run this command and let Git do your detective work.
git config --list --show-origin
It prints each setting and the file it came from. This saves hours of head scratching and blame shifting.
Edit safely with git commands
Do not edit config files by hand unless you like syntax errors and regret. Use git commands to keep things sane. Examples are
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
- For repo only changes run the command in the repo or add
--local
when needed
Troubleshooting tips
If a value refuses to change run git config --list --show-origin
to find the source. Then change the right level using --system
or --global
as appropriate. Back up any config file before manual edits to avoid accidental chaos.
Knowing these locations will speed up debugging of authentication oddities and merge mystery behavior. Now go fix the thing and then take the credit when it starts working.