Five Git config lines that remove weekly annoyances
Global settings that fix upstream errors, prune stale refs, replay conflict fixes, auto-stash and prompt on typos.
Published here , tested on Git 2.54 · 5 sources · Resume reading
Five global config lines that remove annoyances you hit every week. Run them once and every repo on the machine gets them.
Set up auto upstream
No more "has no upstream branch" on a new branch's first push [1].
git config --global push.autoSetupRemote trueYou should see your push succeed on the first try for a new branch.
Prune stale remote refs
Every fetch drops origin/* refs for branches deleted on the remote [2]. Your local branches stay.
git config --global fetch.prune trueYou should see deleted remote branches disappear from git branch -r after your next fetch.
Enable conflict replay
Git replays a conflict fix you already made [3]. Read the replayed result before you git add and commit.
git config --global rerere.enabled trueYou should see "Recorded preimage" when you resolve a conflict, and "Resolved using previous resolution" the next time the same conflict appears.
Auto-stash on rebase
Rebase stashes your uncommitted work and puts it back after [4]. The reapply can still conflict.
git config --global rebase.autoStash trueYou should see "Created autostash" at the start of a rebase when you have uncommitted changes.
Prompt on typos
Typo a command and Git asks "Run 'status' instead [y/N]?" [5].
git config --global help.autoCorrect promptYou should see the prompt when you run something like git stauts.
Check and undo
Check your global config:
git config --global --listUndo one setting:
git config --global --unset rerere.enabledEvery output above is from my test on Git 2.54. Older Git? push.autoSetupRemote needs Git 2.37 or later and help.autoCorrect prompt needs 2.34 or later. Check with git --version.
These five settings are now active on every repo. The next time you push a new branch, fetch after someone deletes one, hit the same merge conflict twice, rebase with uncommitted work, or typo a command, Git handles it.
Send this to the friend who types git push and gets the no upstream branch error every week.
Keep this guide
Filed under Dev tools
Questions about this guide
Do these settings affect existing repositories?
Yes. Global config applies to every repo on the machine unless a repo has its own local override.
Can I undo one setting?
Run git config --global --unset followed by the key name, for example git config --global --unset rerere.enabled.
Sources
- Git docs: push configraw.githubusercontent.com
- Git docs: fetch configraw.githubusercontent.com
- Git docs: rerere configraw.githubusercontent.com
- Git docs: rebase configraw.githubusercontent.com
- Git docs: help configraw.githubusercontent.com