Git: ! [rejected] … (fetch first) — error: failed to push some refs
The remote branch has commits you don’t have locally, so Git refuses to overwrite them. Pull (merge or rebase) first, then push.
Seen on:
Git
Meaning
Your push would not be a fast-forward: someone (or you, from another machine or the GitHub web UI) pushed new commits. Git protects the remote from losing them.
Common causes
- Teammate pushed to the same branch
- You edited files on GitHub (e.g. README) after cloning
- You rewrote local history (rebase/amend) on an already-pushed branch
- Branch protection rejecting the push (different message: protected branch hook declined)
⚡ Quick fix
git pull --rebase origin <branch>thengit push- Resolve conflicts if any,
git rebase --continue - Only if you intentionally rewrote history on your own branch:
git push --force-with-lease
Detailed fix by platform
Git
- Typical sequence:bash
git fetch origin git pull --rebase origin main # fix conflicts if prompted, then: git add . && git rebase --continue git push origin main - Never
--forceon shared branches;--force-with-leaserefuses if someone else pushed in the meantime.
How to diagnose
- Hint — Does the message say “fetch first” or “non-fast-forward”?
- Remote —
git log origin/main..vsgit log ..origin/main - Protection — Is the branch protected?
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026