Knowledge
Git: Updates were rejected (non-fast-forward)
#Git
A rejected push means the remote branch has commits you do not have locally. Git refuses to overwrite them. The fix is to integrate the remote changes first, not to force-push.
Published by Mark van Eijk on June 23, 2026 · 1 minute read
- About the error
- Why do I see this error
- Solution
- Integrate the remote commits, then push
- Do not reach for --force
About the error
! [rejected] main -> main (non-fast-forward)
error: failed to push some refs to '...'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart.
A push can only "fast-forward" when your local branch is a direct continuation of the remote one. If someone else (or another machine of yours) pushed commits in the meantime, your branch has diverged, and Git rejects the push to avoid silently discarding their work.
Why do I see this error
- A teammate pushed to the same branch before you.
- You pushed from another clone or worktree and forgot.
- The remote branch was amended or rebased, so the histories no longer line up.
Solution
Integrate the remote commits, then push
Fetch and merge the remote changes into your branch first:
git pull origin main
git push origin main
If you prefer a linear history without merge commits, rebase your work on top of theirs instead:
git pull --rebase origin main
git push origin main
Resolve any conflicts that come up, then push, this time it fast-forwards cleanly.
Do not reach for --force
It's tempting to "fix" the rejection with git push --force, but on a shared branch that deletes the commits the remote had that you didn't, throwing away your teammate's work. Avoid it.
If you genuinely need to overwrite (for example, after intentionally rebasing your own feature branch), use the safer variant, which refuses if the remote moved in a way you haven't seen:
git push --force-with-lease
--force-with-lease aborts instead of clobbering if someone pushed since your last fetch, making it far safer than a blind --force. The related history error is covered in Git fatal: refusing to merge unrelated histories.
Subscribe to our newsletter
Do you want to receive regular updates with fresh and exclusive content to learn more about web development, hosting, security and performance? Subscribe now!
Related articles
Removing tracked files in Git that should have been ignored
A rejected push means the remote branch has commits you do not have locally. Git refuses to overwrite them. The fix is to integrate the remote changes first, not to force-push.
Change casing of file or directory in Git
A rejected push means the remote branch has commits you do not have locally. Git refuses to overwrite them. The fix is to integrate the remote changes first, not to force-push.