The Hook (The "Byte-Sized" Intro)
Git's factory defaults are cautious — they avoid data loss but don't optimize for modern workflows. A few strategic config changes make Git safer, cleaner, and smarter. pull.rebase keeps your history linear. fetch.prune removes dead branches. push.default current prevents pushing to the wrong branch. Set them once, benefit forever.
📖 What are Safe Defaults?
A curated set of Git configuration values that prevent common mistakes, reduce manual cleanup, and match modern development workflows.
Conceptual Clarity
Recommended safe defaults:
| Setting | Value | What It Does |
|---|---|---|
pull.rebase | true | Rebase local work on pull (no merge commits) |
fetch.prune | true | Remove dead remote-tracking branches on fetch |
push.default | current | Push current branch to same-named remote |
push.autoSetupRemote | true | Auto-track new branches on first push |
merge.conflictstyle | zdiff3 | Show ancestor + both sides in conflicts |
diff.colorMoved | default | Highlight moved lines differently in diffs |
rerere.enabled | true | Remember conflict resolutions |
core.fsmonitor | true | Faster status on large repos |
What rerere does:
"Reuse Recorded Resolution" — when you resolve a conflict, Git remembers the resolution. If the same conflict appears again (e.g., during a rebase), Git applies your previous resolution automatically.
Real-Life Analogy
Safe defaults are like setting your car's mirrors before driving. You could adjust them every time, but setting them once means you're always safe.
Visual Architecture
Why It Matters
- Cleaner history:
pull.rebaseeliminates unnecessary merge commits. - Less clutter:
fetch.pruneremoves branches deleted on remote. - Fewer mistakes:
push.default currentprevents pushing to wrong branches. - Saved time:
rerereresolves repeated conflicts automatically.
Code
# ─── Apply all safe defaults ───
git config --global pull.rebase true
git config --global fetch.prune true
git config --global push.default current
git config --global push.autoSetupRemote true
git config --global merge.conflictstyle zdiff3
git config --global diff.colorMoved default
git config --global rerere.enabled true
# ─── Verify ───
git config --global --list | grep -E "pull|fetch|push|merge|diff|rerere"
# ─── What zdiff3 looks like in a conflict ───
# <<<<<<< HEAD
# your change
# ||||||| common ancestor
# original line
# =======
# their change
# >>>>>>> feature
# The middle section (|||||||) shows what the line was BEFORE
# either side changed it — much easier to resolve!Key Takeaways
pull.rebase true— the single most impactful default for clean history.fetch.prune true— removes stale remote branches automatically.rerere.enabled true— remembers and auto-applies conflict resolutions.merge.conflictstyle zdiff3— shows the ancestor context in conflicts.
Interview Prep
-
Q: What does
pull.rebase truedo and why is it recommended? A: It makesgit pullrebase your local commits on top of the remote changes instead of creating a merge commit. This keeps history linear and avoids cluttering the log with "Merge branch 'main'" commits. -
Q: What is
rererein Git? A: "Reuse Recorded Resolution." When enabled, Git records how you resolve merge conflicts. If the same conflict appears again (common during rebases), Git automatically applies your previous resolution. -
Q: What is
zdiff3conflict style? A: It shows three sections in a conflict: your changes, the common ancestor (original code before either side changed it), and their changes. The ancestor context makes it much easier to understand and resolve the conflict correctly.