Full Byte Developer.

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

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].

bash
git config --global push.autoSetupRemote true

You 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.

bash
git config --global fetch.prune true

You 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.

bash
git config --global rerere.enabled true

You 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.

bash
git config --global rebase.autoStash true

You 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].

bash
git config --global help.autoCorrect prompt

You should see the prompt when you run something like git stauts.

Check and undo

Check your global config:

bash
git config --global --list

Undo one setting:

bash
git config --global --unset rerere.enabled

Every 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

By Full Byte Developer

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

  1. Git docs: push configraw.githubusercontent.com
  2. Git docs: fetch configraw.githubusercontent.com
  3. Git docs: rerere configraw.githubusercontent.com
  4. Git docs: rebase configraw.githubusercontent.com
  5. Git docs: help configraw.githubusercontent.com

Next in this stack