Git config: Aliases, rerere, and Credential Helpers
Five config scopes decide one value at a time. Aliases are user-level shorthand, rerere records conflict resolutions, and credential helpers choose where your secret lives.

Quick Summary
git config is layered: system, global, local, worktree, and command line, with the last one to define a key winning. The same key can therefore have five values at once, and git config --list --show-origin --show-scope is the only reliable way to see which file actually decided the value in effect.
Aliases turn that layer into a personal shorthand — alias.st "status -sb", and ! aliases for shell one-liners. Because they are just config, they do not travel with the repository; a shared includeIf block is how a team standardises them without writing into every clone.
rerere (reuse recorded resolution) records how you resolved a conflict and replays it when the same conflict appears again, which is what makes a long rebase or a repeated merge tolerable. Credential helpers are the third piece of the same file: they decide whether Git asks for a password once per push, once per hour, or never — and where that secret is stored.
Basic Syntax and Core Signatures
# Scopes and inspection
git config --list --show-origin --show-scope # key, file, scope
git config --get user.email
git config --get-regexp '^alias\.'
git config --global --edit # opens ~/.gitconfig
# Writing with types
git config --global core.editor "code --wait"
git config --global --type=bool pull.ff only # --type validates the value
git config --global --add include.path ~/.gitconfig-work
git config --global --unset alias.st
git config --local --fixed-value rerere.enabled true
# Aliases: git subcommands and shell
git config --global alias.st "status -sb"
git config --global alias.lg "log --graph --oneline --decorate --all"
git config --global alias.root "rev-parse --show-toplevel"
git config --global alias.undo '!f() { git reset --hard HEAD@{1}; }; f'
# Configuration that follows the repository
git config --global core.sshCommand "ssh -i ~/.ssh/id_work"
# Rerere
git config --global rerere.enabled true
git config --global rerere.autoUpdate true
git rerere status
git rerere diff
git rerere forget path/to/file# ~/.gitconfig
[user]
name = Ryu
email = dev@example.com
[include]
path = ~/.gitconfig-aliases
[includeIf "gitdir:~/work/"]
path = ~/.gitconfig-work
[url "git@github.com:"]
insteadOf = https://github.com/
[credential]
helper = manager
[credential "https://git.corp.example"]
helper = store# Credential helpers, per host
git config --global credential.helper cache # 15 min, memory
git config --global credential.helper 'cache --timeout=3600'
git config --global credential.helper store # plaintext file
git config --global credential.helper osxkeychain # macOS
git config --global credential.helper libsecret # Linux keyring
git config --global credential.https://github.com.helper managerKey Comparison Table
| Scope | File | Applies to | Overrides |
|---|---|---|---|
--system | /etc/gitconfig | Every user on the machine | Nothing |
--global | ~/.gitconfig, $XDG_CONFIG_HOME/git/config | Every repository of this user | System |
--local | .git/config | One repository | Global |
--worktree | .git/worktrees/<id>/config.worktree | One worktree | Local |
-c key=value | Nowhere (one process) | One command | Everything |
| Credential helper | Storage | Persistence | Notes |
|---|---|---|---|
cache | Memory | --timeout seconds, default 900 | No disk write, lost on reboot |
store | ~/.git-credentials, plaintext | Until deleted | Mode 600 only; avoid on shared machines |
osxkeychain / manager | OS keychain | Until removed | Best default on macOS and Windows |
libsecret | Secret Service | Until removed | Needs a running keyring |
| none | Prompt each time | Session only | Use GIT_TERMINAL_PROMPT=0 in CI |
Practical Edge Cases and Deep Dives
1. Conditional includes for work and personal repositories
[includeIf "gitdir:~/work/"]
path = ~/.gitconfig-work
[includeIf "gitdir/i:~/Clients/"]
path = ~/.gitconfig-clients
[includeIf "onbranch:release/"]
path = ~/.gitconfig-releasegitdir: matches the location of the repository, gitdir/i: ignores case, and a path ending in / matches that directory and everything below it. Values from an included file override the ones before it in the parent file, so the work email replaces the personal one for repositories under ~/work/. This is the practical way to stop committing with a personal address to a company repository without remembering -c user.email on every command.
2. Aliases that do not behave like subcommands
git config --global alias.root "rev-parse --show-toplevel" # runs as a subcommand
git config --global alias.root '!pwd' # runs as a shell command
git root # prints the top levelA ! alias runs in a shell at the top level of the repository (or the current directory outside one), with GIT_PREFIX holding the subdirectory you were in. That is why alias.ll '!ls' lists the repo root rather than your current directory. An alias may not shadow a built-in command — alias.commit is ignored with a warning — and an alias cannot take positional arguments other than by appending: git lg -5 works because the arguments are appended, while a shell alias needs a function form ('!f() { …; }; f') to place them.
3. rerere: turning a repeated conflict into a one-time decision
git config --global rerere.enabled true
git rebase main
# CONFLICT (content): Merge conflict in src/parser.ts
# Resolved 'src/parser.ts' using previous resolution. <- second timererere stores pre- and post-images keyed by the conflict itself, so the same textual conflict resolves itself on the next rebase, merge, or cherry-pick. rerere.autoUpdate stages the recorded resolution so it is included in the commit. Three practical points: it only helps when the conflict is genuinely identical, it works per-repository (the recordings live in .git/rr-cache), and git rerere forget <path> is the escape when the recorded resolution is wrong — otherwise it will confidently reapply a bad fix.
4. Why the credential helper keeps asking
git config --list --show-origin | grep credential
# file:~/.gitconfig credential.helper=manager
# file:.git/config credential.helper=store
GIT_TRACE=1 GIT_CURL_VERBOSE=1 git fetch
# 17:31:02.917 ... run_command: run-command.c:657 trace: run_command: 'git-credential-store get'Multiple helpers form a list that is asked in order, and an empty value resets the list: helper = manager, then helper = (empty), then helper = store leaves only store. A repository-local helper silently overrides a global one, which is the usual cause of a credential prompt returning after the keychain was configured. git credential fill with a prepared input block shows exactly which helper answered.
5. URL rewriting, and the trap of two insteadOf rules
git config --global url."git@github.com:".insteadOf "https://github.com/"
git config --global url."https://github.com/".insteadOf "git@github.com:"The second rule does not just rewrite your pushes back to HTTPS; it rewrites the rewritten URL, so every operation bounces between the two forms. insteadOf matches prefixes, and the longest matching prefix wins, so a narrower rule (url."ssh://git@github.com:2222/".insteadOf "https://github.com/") beats a broader one. CI systems use this to swap HTTPS for SSH with a deploy key — but the rule is global, so a machine that also needs HTTPS for a public mirror should scope it with includeIf.
6. Checking configuration that a script depends on
git config --type=bool --get pull.rebase || echo "unset"
git config --type=int --get gc.auto
git config --get-all credential.helper
git -c core.pager=cat -c color.ui=false log -1--type is worth adding to any script that reads config: it rejects yes where a number is expected instead of silently treating the key as unset, and it normalises booleans (true, yes, on, 1) to a single value. git -c applies a setting to one invocation without writing anything, which is how a build script should force -c protocol.version=2 or disable a pager rather than mutating the user's config.
Common Git Operation Mistakes
| Symptom | Cause | Fix |
|---|---|---|
| Setting has no effect | Defined in a higher-precedence scope | git config --list --show-origin |
| Alias not found after cloning | Aliases are user config, not repository data | Recreate, or commit an include file |
alias.commit ignored | Built-in commands cannot be aliased | Use a different name |
| Credential prompt every push | Helper absent, or reset by an empty value | Check --get-all credential.helper |
| Token stored in plaintext unexpectedly | credential.helper store in a lower-precedence file | Switch to the OS keychain, delete ~/.git-credentials |
| Wrong author email on a commit | Conditional include not matching | git config --show-origin user.email |
| rerere reapplies a bad resolution | Recorded conflict reused | git rerere forget <path> |
insteadOf loops between two URLs | Two rules rewriting each other | Delete one, use GIT_TRACE to confirm |
Script reads yes as a number | No --type given | git config --type=int --get <key> |
Try matching browser tools
All toolsSmall utilities that fit Git work — they run entirely in this browser tab, so nothing you paste leaves your device.
Related Git guides
All Git guidesGit Hooks: pre-commit, commit-msg, and Husky Automation
Hooks live in .git/hooks, which a clone never receives, so core.hooksPath and Husky are how they travel. Exit codes abort the operation, and every hook is bypassable.
Git bisect: Binary Search, Automated Scripts, and Bug Hunting
Mark one bad and one good commit and Git halves the range each step. bisect run automates it through exit codes, and monotonicity is the assumption that must hold.
Git ignore: Patterns, Negation, and Untracking Cached Files
Patterns are relative and last match wins, but a negation cannot revive a file inside an excluded directory. Ignore rules never touch tracked files: rm --cached first.
Git worktree: Multiple Checked-Out Branches in One Repository
A linked worktree has its own HEAD, index, and files while sharing objects and refs. One branch per worktree, prune for deleted directories, and submodules that stay empty.
More in Git
All Git guidesThe guides filed next to this one in Git, in library order.