Skip to content

/errors/git/failed-to-push-some-refs

error: failed to push some refs (rejected, fetch first)

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash) · git version 2.55.0.windows.5updated 2026-10-20
tool
Git
exit code
1
versions
Git 2.x
os
linux, macos, windows

git push fails with ! [rejected] main -> main (fetch first) and error: failed to push some refs when the remote branch contains commits that your local branch does not have. Git refuses to overwrite them. Fetch those commits and integrate them, then push again.

Reproduce the error

Two clones of the same repository; the first one pushes, then the second one tries to:

bash
git init -q --bare remote.git
git clone -q remote.git alice 2>/dev/null && cd alice
git switch -q -c main && echo one > a.txt && git add a.txt && git commit -qm "one" && git push -q origin main
cd .. && git clone -q -b main remote.git bob && cd alice
echo two >> a.txt && git commit -qam "two" && git push -q origin main
cd ../bob
echo three > b.txt && git add b.txt && git commit -qm "three"
git push origin main

Output · exit 1

To /tmp/work/remote.git
 ! [rejected]        main -> main (fetch first)
error: failed to push some refs to '/tmp/work/remote.git'
hint: Updates were rejected because the remote contains work that you do not
hint: have locally. This is usually caused by another repository pushing to
hint: the same ref. If you want to integrate the remote changes, use
hint: 'git pull' before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

Fix: rebase onto the remote, then push

bash
git init -q --bare remote.git
git clone -q remote.git alice 2>/dev/null && cd alice
git switch -q -c main && echo one > a.txt && git add a.txt && git commit -qm "one" && git push -q origin main
cd .. && git clone -q -b main remote.git bob && cd alice
echo two >> a.txt && git commit -qam "two" && git push -q origin main
cd ../bob
echo three > b.txt && git add b.txt && git commit -qm "three"
git pull --rebase -q origin main
git push -q origin main && git log --oneline

Output

2b24f0e three
e76c590 two
e057f16 one

git pull --rebase replays your local commits on top of the remote ones, so the push becomes a fast-forward. A plain git pull (merge) works too, but adds a merge commit.

Sources