Sub topic 15
Verifying your setup and fixing common problems
This chapter assumes you have Git installed, can use a terminal, and know what a repository and a commit are. It also assumes you have read the earlier chapters on scopes, precedence and --show-origin. Here you will check that your configuration works and learn how to trace the usual failures back to their cause.
A short verification routine
After a first-time setup, run three checks. Each one answers a different question.
- Is the identity correct, and which file supplies it?
- Do the other settings you chose have the values you expect?
- Does a real commit carry the right author?
git config --show-origin --get user.name
git config --show-origin --get user.email
git config --show-origin --get init.defaultBranch
git config --show-origin --get core.editorEach command prints the file path and then the value. If a command prints nothing and exits with status 1, the key is not set in any file Git reads.
To see everything at once, including overridden values, use the full listing:
git config --list --show-originWhen a key appears more than once, the last line wins. Git reads system, then global, then local files, so a later line comes from a more specific scope.
For the third check, make a throwaway repository and look at the result:
git init /tmp/config-check
cd /tmp/config-check
git commit --allow-empty -m "Check identity"
git log -1 --format="%an <%ae>"
git branch --show-currentThe author line should show your name and email. The branch should be the name you set in init.defaultBranch.
Common problems
| Symptom | Likely cause | Fix |
|---|---|---|
| Commits show the wrong email in one project | A local `user.email` overrides the global one | Run `git config --show-origin --get user.email` inside the repository, then change or unset the local value |
| Git asks for your name and email at commit time | `user.name` or `user.email` is not set | Set both with `git config --global` |
| New repositories still start on `master` | `init.defaultBranch` is not set, or the repository already existed | Set the key. It only affects repositories created afterward |
| Commit hangs or aborts with an editor error | The `core.editor` command is missing or lacks a wait flag | Use a command that blocks, such as `code --wait` |
| A setting seems ignored | Misspelled key, or a more specific scope overrides it | Compare `--list --show-origin` output with the key you typed |
| Work identity not applied under `~/work/` | `includeIf` path or trailing slash is wrong | Check the `gitdir:` pattern and the include file path |
Checking an includeIf rule
A conditional include only applies when you run Git inside a matching repository. From your home directory, git config --get user.email will show the global value, which is expected. Test from inside a repository:
cd ~/work/some-project
git config --show-origin --get user.emailIf the output names ~/.gitconfig-work, the rule matched. If it names ~/.gitconfig, check that the gitdir: pattern ends with a slash and that the include file exists.
Reading errors
A malformed file produces an error that names the file and line, such as fatal: bad config line 4 in file /home/ada/.gitconfig. Open that file with git config --global --edit and fix the line. Section headers need square brackets, and values with spaces inside commands should be quoted.
Exercise
Commits in one repository show [email protected], but your global file sets [email protected]. What single command shows which file supplies the value, and what two ways can you fix it?
Show answer
Run git config --show-origin --get user.email inside the repository. It will show .git/config, which is the local scope. Either remove the override with git config --local --unset user.email, or correct it with git config --local user.email "[email protected]".
Exercise
You set init.defaultBranch to main, but an existing repository still uses master. Why?
Show answer
The setting only applies when a repository is created with git init. Existing repositories keep their current branch name. Rename it with git branch -m main if you want to change it.