← Back to all fixes
Git

Branches have diverged — push rejected

The Issue

`git push` fails: `rejected — non-fast-forward: Updates were rejected because the remote contains work that you do not have locally`

Root Cause

Someone else pushed to the same branch, or you pushed from another machine. Your local branch is behind the remote.

How to Fix
  1. Pull first: `git pull --rebase origin main` (rebase keeps history linear)
  2. Or: `git pull origin main` (creates a merge commit)
  3. Resolve any conflicts that arise, then push again
  4. Do NOT use `git push --force` unless you are the only one on that branch — it overwrites others' work
  5. Use `--force-with-lease` if you must force push: safer, fails if someone else pushed