Executive Summary & Root Cause Analysis: The error
fatal: Need to specify how to reconcile divergent branches(preceded byhint: You have divergent branches and need to specify how to reconcile them) occurs when runninggit pullin Git 2.27 or newer while your local branch and the remote tracking branch have both accumulated new, separate commits. Because a clean fast-forward merge is impossible when histories diverge, modern Git refuses to guess whether you want a merge commit, a rebase, or an abort until you explicitly choose a reconciliation strategy. Common triggers include: (1) committing locally while a teammate pushes to the same branch, (2) amending or rebasing an already-pushed commit locally, and (3) fresh Git installations lacking a globalpull.rebaseorpull.ffconfiguration.
Step 1: Quick Fix – Specify a One-Time Pull Strategy
To resolve the error immediately for the current pull without changing your global Git settings, pass one of three explicit reconciliation flags to git pull:
# Option A: Merge remote changes into your local branch (creates a merge commit)
git pull --no-rebase
# Option B: Rebase your local commits cleanly on top of the remote branch (linear history)
git pull --rebase
# Option C: Abort if fast-forward is not possible (safest if you want to inspect first)
git pull --ff-only
If you choose --rebase and encounter a conflict, resolve the conflicted file, stage it with git add <file>, and run git rebase --continue.
Step 2: Permanent Configuration – Set Your Default Pull Behavior
To prevent this prompt from interrupting future pulls, configure your preferred default strategy globally (or per-repository by omitting --global):
# Strategy 1: Default to standard merge commits (Classic Git behavior)
git config --global pull.rebase false
# Strategy 2: Default to rebase (Recommended for clean, linear commit history)
git config --global pull.rebase true
# Strategy 3: Only allow fast-forward pulls (Forces manual review on divergence)
git config --global pull.ff only
Pro Tip: If you use pull.rebase true and frequently pull while having uncommitted local edits, also enable rebase.autoStash so Git automatically stashes and reapplies your working tree changes:
git config --global rebase.autoStash true
Step 3: Alternative Workarounds – Manual Fetch & History Inspection
When you are unsure why your branch diverged (for instance, after a teammate force-pushed to a shared feature branch), avoid blind pulling and inspect the exact commit difference first:
- Fetch remote updates without modifying your local branch:
git fetch origin - Compare local-only vs. remote-only commits:
# Show commits present on remote but missing locally git log HEAD..origin/main --oneline # Show commits present locally but missing on remote git log origin/main..HEAD --oneline - Realign with remote if your local commits are obsolete or replaced:
# Create a safety backup branch first, then reset to match remote exactly git branch backup-local-state git reset --hard origin/main
Verification & Testing Steps
Confirm that your global pull configuration is saved and that your local branch is synchronized with its remote upstream:
# Verify active pull configuration
git config --get-regexp '^pull\.'
# Confirm branch tracking status shows zero divergence
git status -sb
# Inspect recent commit graph for clean integration
git log --graph --oneline -n 10
Summary Comparison Table
| Pull Strategy | CLI Flag / Config | Commit History Result | Best Used For |
|---|---|---|---|
| Merge | --no-rebase / pull.rebase false |
Preserves both histories via merge commit | Teams preferring explicit merge bubbles |
| Rebase | --rebase / pull.rebase true |
Linear history (replays local commits on top) | Clean feature branches & PR workflows |
| Fast-Forward Only | --ff-only / pull.ff only |
Fails safely if branches have diverged | Strict main/release branches & CI scripts |
| Manual Fetch & Reset | git fetch && git reset --hard |
Discards local divergence to match remote | Recovering from upstream force-pushes |
Leave a Reply