Lesson Completion
Back to course

Safe Defaults

Beginner
7 minutes4.8Git

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:

SettingValueWhat It Does
pull.rebasetrueRebase local work on pull (no merge commits)
fetch.prunetrueRemove dead remote-tracking branches on fetch
push.defaultcurrentPush current branch to same-named remote
push.autoSetupRemotetrueAuto-track new branches on first push
merge.conflictstylezdiff3Show ancestor + both sides in conflicts
diff.colorMoveddefaultHighlight moved lines differently in diffs
rerere.enabledtrueRemember conflict resolutions
core.fsmonitortrueFaster 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

flowchart TD DEFAULTS["⚙️ Safe Defaults"] --> PULL["pull.rebase true<br/>Clean history"] DEFAULTS --> PRUNE["fetch.prune true<br/>Remove dead branches"] DEFAULTS --> RERERE["rerere.enabled true<br/>Auto-resolve conflicts"] DEFAULTS --> PUSH["push.autoSetupRemote<br/>Easy first push"] style DEFAULTS fill:#0f3460,stroke:#53d8fb,color:#53d8fb

Why It Matters

  • Cleaner history: pull.rebase eliminates unnecessary merge commits.
  • Less clutter: fetch.prune removes branches deleted on remote.
  • Fewer mistakes: push.default current prevents pushing to wrong branches.
  • Saved time: rerere resolves repeated conflicts automatically.

Code

bash
# ─── 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 true do and why is it recommended? A: It makes git pull rebase 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 rerere in 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 zdiff3 conflict 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.

Topics Covered

Git ConfigurationBest Practices

Tags

#git#config#defaults#safety

Last Updated

2026-02-13