Skip to content

Stale remote-tracking branch after force push

Quick summary

A teammate force-pushed to a shared branch, and your local remote-tracking ref still points to the old history — pulling creates conflicts or duplicate commits.

Why this happens

  • A teammate ran git push --force which rewrote the remote branch history, but your local origin/branch ref is stale

  • You have local commits on top of the old remote history that will conflict or duplicate when you pull the new history

  • You fetched with --prune which removed the old tracking ref but your local branch still expects the old upstream

Minimal example

✗ Broken code
# teammate force-pushed origin/feature
git pull  # merges old and new history, creating duplicates
✓ Fixed code
git fetch origin --prune
git rebase origin/feature  # replay local commits on new remote history

Fetching with --prune updates the tracking ref to the force-pushed history, then rebasing replays your local commits cleanly without duplicates.

How to diagnose

  • Run git fetch origin --prune to update all remote-tracking refs and remove stale ones

  • Run git log --oneline --graph origin/branch..HEAD to see local commits that are not on the updated remote

  • Compare git log --oneline HEAD and git log --oneline origin/branch to understand the divergence after force push

How to fix

  • Reset your local branch to match the new remote history with git reset --hard origin/branch, then re-apply your local commits

  • Rebase your local commits onto the new remote with git fetch && git rebase origin/branch to avoid duplicate commits

  • If your local commits were already force-pushed away, recover them from git reflog and cherry-pick onto the new history

How to prevent

  • Use --force-with-lease instead of --force to prevent overwriting teammates' work without their awareness

  • Communicate with your team before force-pushing and have everyone fetch --prune immediately after

Related Resources

Related Glossary

Related Lessons

← Back to language