Skip to content

Non-Fast-Forward Push

Error message

                ! [rejected] main -> main (non-fast-forward)
              

Quick summary

Your local and remote branches have diverged — the remote has commits you do not have, and you have commits it does not have.

Why this happens

  • Someone else pushed commits to the remote that you have not integrated

  • You rebased or amended locally, rewriting history

  • Your local branch and remote branch have divergent histories

Minimal example

✗ Broken code
git push origin main  # ! [rejected] main -> main (non-fast-forward)
✓ Fixed code
git pull --rebase origin main
git push origin main  # succeeds

Pull with rebase to integrate remote changes first, then push. Use --force-with-lease only if you intentionally rewrote history.

How to diagnose

  • Run git fetch to download remote changes

  • Check git log origin/main..main to see your local-only commits

  • Check git log main..origin/main to see remote-only commits

How to fix

  • Run git pull --rebase to replay your commits on top of the remote

  • Resolve any conflicts from the rebase, then git rebase --continue

  • Run git push again after the rebase succeeds

  • If you intentionally rewrote history, use git push --force-with-lease

How to prevent

  • Pull before you push to stay in sync

  • Never rebase or amend commits that have been pushed to shared branches

  • Communicate with your team about history rewrites

Related Resources

Related Glossary

Related Lessons

← Back to language