Useful Git Settings
Git settings are named values, such as user.email or pull.rebase, that change how Git behaves. They are read with and written by the git config command, and stored in plain text files at three levels: for the whole computer, for your user account, and for one repository. "Git Config: Setting Up Git" covered the first steps. This lesson covers the settings experienced developers change, how to see where a value comes from, and how to use different settings automatically in different folders.
Think of a new phone. The manufacturer sets defaults, you set your own preferences, and some apps have settings of their own that override yours inside that app. Git settings work the same way: the most specific setting wins.
The Three Levels
| Level | Option | File | Applies to |
|---|---|---|---|
| System | --system | /etc/gitconfig (or Git's install folder on Windows) | Every user on the computer |
| Global | --global | ~/.gitconfig (or ~/.config/git/config) | Every repository of your user |
| Local | --local (the default when writing inside a repository) | .git/config | One repository |
When the same setting appears at several levels, local overrides global, and global overrides system. --show-origin and --show-scope reveal where each value comes from:
mkdir fee-tracker
cd fee-tracker
git init --quiet
git config --global pull.rebase true
git config pull.rebase false
git config --show-scope --show-origin --get-all pull.rebase
git config pull.rebaseglobal file:/home/navika/.gitconfig true
local file:.git/config false
falseExplanation: pull.rebase is set twice: true globally and false in this repository. --get-all lists both, with their file and level. A plain git config pull.rebase prints the value Git actually uses: the local one wins.
Settings Worth Knowing
| Setting | Recommended | Description |
|---|---|---|
init.defaultBranch | main | It is used to name the first branch of new repositories. |
pull.rebase | true | It is used to rebase local commits on pull, instead of creating merge commits. |
push.autoSetupRemote | true | It is used to set the upstream on the first push of a branch automatically. |
push.followTags | true | It is used to push annotated tags together with the commits they point to. |
fetch.prune | true | It is used to remove copies of branches deleted on the server. |
rebase.autoStash | true | It is used to stash and restore uncommitted changes around a rebase. |
rebase.updateRefs | true | It is used to move stacked branches along during a rebase. |
merge.conflictStyle | zdiff3 | It is used to show the original lines in conflict markers. |
rerere.enabled | true | It is used to remember conflict resolutions and reuse them. |
diff.algorithm | histogram | It is used to produce clearer diffs for moved or repeated code. |
diff.colorMoved | default | It is used to show moved lines in a different color. |
help.autocorrect | prompt | It is used to suggest (and optionally run) the right command after a typo. |
core.editor | your editor | It is used to choose the editor for messages. |
branch.sort | -committerdate | It is used to list the most recently used branches first in git branch. |
Set the ones you want with --global once. The next sections show two of them in action.
rerere: Reuse Recorded Resolution
rerere ("reuse recorded resolution") makes Git remember how you resolved a conflict. If the same conflict appears again, for example when you rebase a branch a second time or redo a merge, Git applies your earlier resolution automatically.
git config rerere.enabled true
echo 'Late fee: $250' > fees.txt
git add fees.txt
git commit --quiet -m "Add the late fee"
git switch --quiet -c feature/late-fee
echo 'Late fee: $300' > fees.txt
git commit --quiet -am 'Raise the late fee to $300'
git switch --quiet main
echo 'Late fee: $275' > fees.txt
git commit --quiet -am 'Raise the late fee to $275'
git merge feature/late-feeAuto-merging fees.txt
CONFLICT (content): Merge conflict in fees.txt
Recorded preimage for 'fees.txt'
Automatic merge failed; fix conflicts and then commit the result.Recorded preimage for 'fees.txt': rerere saved the conflict. Navika resolves it, which rerere records too, and then, to test the feature, undoes the merge completely:
echo 'Late fee: $300' > fees.txt
git add fees.txt
git commit --quiet --no-editRecorded resolution for 'fees.txt'.Recorded resolution means rerere saved how the conflict was resolved. Now the merge is undone and run again:
git reset --quiet --hard HEAD~1
git merge feature/late-feeAuto-merging fees.txt
CONFLICT (content): Merge conflict in fees.txt
Resolved 'fees.txt' using previous resolution.
Automatic merge failed; fix conflicts and then commit the result.cat fees.txtLate fee: $300Explanation: the second merge hit the same conflict, and Git said Resolved 'fees.txt' using previous resolution. The file already has the resolved content. Git still stops, so that you can check the result and git add it, but the work is done. With rebases that replay many commits, or long-lived branches merged repeatedly, rerere saves a lot of time.
help.autocorrect: Typo Rescue
git merge --abort
git -c help.autocorrect=immediate stauts -sWARNING: You called a Git command named 'stauts', which does not exist.
Continuing under the assumption that you meant 'status'.With immediate, Git runs the only close match after a typo. prompt asks first, a number such as 10 waits that many tenths of a second, and never (or unset) only prints suggestions. git -c <name>=<value> sets a value for one command only, without changing any file.
Conditional Includes: Work and Personal Identities
Many developers use one computer for work and personal projects, with a different email for each. includeIf loads an extra config file only for repositories in certain folders. Navika keeps work repositories under ~/work/:
cd ..
mkdir -p ~/work
cat > ~/.gitconfig-work <<'EOF'
[user]
email = navika@school.example.com
EOF
git config --global includeIf."gitdir:~/work/".path ~/.gitconfig-work
git init --quiet ~/work/school-portal
git init --quiet personal-site
echo "Work: $(git -C ~/work/school-portal config user.email)"
echo "Personal: $(git -C personal-site config user.email)"Work: navika@school.example.com
Personal: navika@example.comExplanation: inside ~/work/, Git also reads ~/.gitconfig-work, whose email overrides the global one. Everywhere else, the global email is used. The trailing / in gitdir:~/work/ means "this folder and everything below it". Other conditions are gitdir/i: (case-insensitive, useful on Windows and macOS), onbranch:<pattern> and hasconfig:remote.*.url:<pattern> (for example, every repository whose remote is on your company's server).
Pager, Colors and Prompt
| Setting or tool | Description |
|---|---|
core.pager | It is used to choose the pager for long output, such as less -FRX (exits at once if the output fits on screen). |
pager.<command> false | It is used to turn the pager off for one command, for example pager.branch false. |
color.ui | It is used to turn colors on (auto, the default) or off (never). |
| Shell prompt | Shows the current branch and state. Git ships git-prompt.sh for Bash and Zsh, and tools like Starship or Oh My Posh do it for any shell. |
A prompt that shows fee-tracker (main *) (a branch, and * for unstaged changes) prevents many "wrong branch" mistakes.
Credential Storage
Git can remember HTTPS tokens in several ways, with different security:
| Helper | Stores the token | Security |
|---|---|---|
manager (Git Credential Manager) | In the operating system's secure store | Good: encrypted, supports browser sign-in |
osxkeychain | In the macOS Keychain | Good: encrypted |
libsecret | In the Linux desktop's keyring | Good: encrypted |
cache --timeout=<seconds> | In memory, for a limited time | Fair: never written to disk |
store | In a plain text file, ~/.git-credentials | Poor: anyone who can read the file has the token |
Avoid store on shared or unencrypted computers. SSH keys with a passphrase and an agent ("Adding an SSH Key") avoid storing tokens at all.
Common Mistakes
Setting something with --global and wondering why it doesn't apply. A local value overrides it. Check with --show-origin.
A wrong email on work commits. Use includeIf so that the identity follows the folder.
Forgetting the trailing / in gitdir:. Without it, the condition matches only that exact repository folder.
credential.helper store on a shared computer. The token is in plain text. Use the system's secure store.
Copying a huge .gitconfig from the internet. Settings you don't understand can surprise you. Add them one at a time.
Under the Hood
Config files use a simple INI-like format: [section] or [section "subsection"] headers, then key = value lines. Git reads the system file, then the global files, then the local .git/config, then any worktree-specific file, applying include and includeIf where they appear, and the last value read for a single-valued key wins. That reading order is why local overrides global. GIT_CONFIG_COUNT, GIT_CONFIG_KEY_<n> and GIT_CONFIG_VALUE_<n> environment variables and -c on the command line are applied after all files, which is how a one-off git -c setting beats everything else.
Interview Corner
What are the levels of Git configuration?
System (/etc/gitconfig), global (~/.gitconfig) and local (.git/config), plus worktree-specific config and one-off values with git -c. More specific levels override less specific ones: local over global over system.
How do you find out where a Git setting comes from?
git config --show-origin --show-scope <name> (or --list --show-origin) prints each value with its file and level.
How do you use a different email for work repositories automatically?
Put the work email in a separate file and include it conditionally in ~/.gitconfig with [includeIf "gitdir:~/work/"] and path = ~/.gitconfig-work. It applies to every repository under that folder.
What is git rerere?
"Reuse recorded resolution": with rerere.enabled=true, Git records how you resolve each conflict and automatically reapplies the same resolution when the identical conflict appears again, such as during repeated rebases or merges.
Which credential helper should you use?
One that uses the operating system's secure storage: Git Credential Manager (manager), osxkeychain or libsecret. Avoid store, which saves tokens in plain text.
Practice
Challenge: a second work folder. Navika also works for a tutoring center, whose repositories are under ~/tutoring/, with the email navika@tutoring.example.com. Add a second conditional include, then print the email used in ~/tutoring/timetable, in ~/work/school-portal and in personal-site.
What does Git print? Before you open the solution, decide which file each repository reads.
Show solution
cat > ~/.gitconfig-tutoring <<'EOF'
[user]
email = navika@tutoring.example.com
EOF
git config --global includeIf."gitdir:~/tutoring/".path ~/.gitconfig-tutoring
git init --quiet ~/tutoring/timetable
echo "Tutoring: $(git -C ~/tutoring/timetable config user.email)"
echo "Work: $(git -C ~/work/school-portal config user.email)"
echo "Personal: $(git -C personal-site config user.email)"Tutoring: navika@tutoring.example.com
Work: navika@school.example.com
Personal: navika@example.comEach folder gets its own identity: the tutoring and work repositories read their included files, and the personal one uses the global email. A third employer would just be one more includeIf line.
Checkpoint. Set up a work and a personal identity that switch automatically by folder, enable rerere, fetch.prune and pull.rebase globally, and check every value's origin with git config --list --show-origin --show-scope.
Key Takeaways
Quick reference
| Command | It is used to |
|---|---|
git config --global <name> <value> | Set a value for your user |
git config <name> <value> | Set a value for this repository |
git config --show-origin --show-scope <name> | See where a value comes from |
git config --list --show-origin | List every setting with its file |
git config --global --unset <name> | Remove a setting |
git -c <name>=<value> <command> | Use a value for one command |
git config --global includeIf."gitdir:~/work/".path <file> | Include a file for one folder |
Was this tutorial helpful?