Git: failed to push some refs (rejected)
Your push is rejected with 'failed to push some refs' and a note about non-fast-forward. It means the remote has commits you don't. Here's how to pull them in safely and push again.
You push and Git bounces it back:
! [rejected] main -> main (non-fast-forward)
error: failed to push some refs to 'origin'
hint: Updates were rejected because the remote contains work that you do
not have locally.
This is Git protecting shared history. The remote branch has commits that your local branch doesn't — usually a teammate pushed, or you committed from another machine. Git won't let you overwrite that work, so it rejects the push.
Step 1: Get the remote's commits
Bring the missing commits down and replay yours on top:
git pull --rebase origin main
--rebase keeps history linear: it puts the remote's commits first, then re-applies your commits after them. (A plain git pull also works but adds a merge commit.)
Step 2: Resolve conflicts if they appear
If you and the remote changed the same lines, the rebase pauses:
git status # shows the conflicted files
# edit the files, keep the right lines, remove the <<<< ==== >>>> markers
git add <file>
git rebase --continue
Repeat until the rebase finishes cleanly.
Step 3: Push again
Now your branch is ahead of the remote in a straight line, so the push fast-forwards:
git push origin main
The one thing not to do
Do not reach for
git push --forceto make the error go away. Force-pushing overwrites the remote's history and erases whatever your teammate pushed. If you truly must force (e.g. after rebasing your own feature branch), use--force-with-lease, which refuses to clobber commits you haven't seen.
The checklist
git pull --rebase origin <branch>— take the remote's work first.- Resolve any conflicts,
git add,git rebase --continue. git push— it fast-forwards now.- Never blind
--force; use--force-with-leaseonly on your own branches.
Frequently Asked Questions
Why is my Git push rejected as "non-fast-forward"?
The remote branch has commits your local branch doesn't — someone pushed, or you committed elsewhere. Git refuses to overwrite that work. Run git pull --rebase origin <branch> to take their commits first, then push.
Should I use git push --force to fix "failed to push some refs"?
No, not on a shared branch — a force push erases whatever your teammates pushed. Pull and rebase instead. If you genuinely must force after rebasing your own feature branch, use --force-with-lease, which refuses to clobber commits you haven't seen.
What does "--force-with-lease rejected (stale info)" mean?
The remote moved since your last fetch, so the safety check blocked the push to protect those new commits. Run git fetch, review what changed, and only retry once you're sure you won't destroy someone else's work.
Stop reading, start building
This pairs with a hands-on BytExplorer course — do it on your own machine and actually keep the skill.