Divergent Branches After git pull
About
Sometimes when we run git pull
, we see an error like this:
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:
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 will merge the remote changes into our local branch.
A merge commit is created.
Preserves both sets of commits.
Option 2: Rebase Strategy
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
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:
Permanent Solution
To avoid this message in future, set our preferred strategy globally:
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):
Use with caution — this overwrites our local commits.
Last updated
Was this helpful?