Git3 min read2026-03-01
Git Push Rejected (non-fast-forward)
Fix 'error: failed to push some refs to... Updates were rejected because the tip of your current branch is behind'.
Error Code / Stack Trace
! [rejected] main -> main (non-fast-forward)
error: failed to push some refs to 'github.com/repo.git'Problem Overview
Git rejects your git push because the remote repository contains commits that your local branch does not have.
Why Does This Happen?
- A teammate pushed commits to the remote branch while you were working locally.
- You merged a pull request directly on GitHub/GitLab and your local clone is out of sync.
Step-by-Step Solution
Step 1: Pull remote commits with rebase
Fetch remote commits and replay your local commits cleanly on top.
bash
git pull --rebase origin mainStep 2: Push your branch safely
Now that your local branch has fast-forward history, push normally.
bash
git push origin mainCommon Mistakes to Avoid
- •Blindly using 'git push --force' on shared branches like main, which overwrites colleagues' commits.
Prevention & Best Practices
- If force-pushing on a personal feature branch is necessary, always use 'git push --force-with-lease'.
Frequently Asked Questions
Why is --force-with-lease safer than --force?
--force-with-lease refuses to overwrite remote commits if someone else pushed changes you have not seen yet.
Related Developer Solutions & Tools
Recommended Tools
Related Error Fixes