Divergent Branches After git pull
About
Sometimes when we run git pull
, we see an error like this:
hint: You have divergent branches and need to specify how to reconcile them.
fatal: Need to specify how to reconcile divergent branches.
When Does This Happen?
1. Local Commits + Remote Commits
We have made commits locally, and meanwhile, someone else has pushed new commits to the remote. Now both have different changes.
2. Someone Force Pushed to the Branch
Another developer rewrote the history of the branch using git push --force
, replacing the previous commits on the remote. Our local branch still has the old history, causing divergence.
Example output when force push has occurred:
+ abc123...def456 feature/xyz -> origin/feature/xyz (forced update)
The +
sign and (forced update)
indicate a force push.
How to Fix ?
We need to tell Git how to reconcile the divergent histories. We can do this in one of three ways:
Option 1: Merge Strategy
git config pull.rebase false
git pull
Git will merge the remote changes into our local branch.
A merge commit is created.
Preserves both sets of commits.
Option 2: Rebase Strategy
git config pull.rebase true
git pull
Git will rebase our local commits on top of the updated remote branch.
Keeps a clean, linear history.
Preferred in many modern workflows.
Option 3: Fast-Forward Only
git config pull.ff only
git pull
Only succeeds if our branch can be fast-forwarded (i.e., no divergence).
Otherwise, it will fail and ask us to resolve the divergence manually.
One-Time Fix Without Changing Config
If we just want to resolve the issue once:
git pull --rebase # or
git pull --no-rebase # or
git pull --ff-only
Permanent Solution
To avoid this message in future, set our preferred strategy globally:
git config --global pull.rebase true # Always rebase
git config --global pull.rebase false # Always merge
git config --global pull.ff only # Only allow fast-forward pulls
When We Don't Care About Local Changes
If we want to discard our local changes and align with remote (e.g., after force push):
git fetch origin
git reset --hard origin/your-branch-name
Use with caution — this overwrites our local commits.
Last updated
Was this helpful?