FIX · ERROR

"! [rejected]
failed to push some refs."

You pushed and Git refused. The remote branch has commits that your copy does not have, usually because someone else (or you, from another machine) pushed first. Git will not overwrite them.

git pullgit fetchnon-fast-forward--force-with-lease

The short answer

bring theirs in first
1

Why

The remote branch moved on. Your push would drop their commits, so Git says no.

2

Fix

git pull brings their commits in (and may ask for a merge message). Then git push.

3

Do not

Do not reach for git push --force. It can wipe out your teammate's work.

"fetch first" and "non-fast-forward" are the same problem. Git says "fetch first" when it has not yet seen the remote commits, and "non-fast-forward" once you have fetched them.

What it looks like

real Git 2.34.1 output

Real Git prints the second line with your own remote URL. The hint wording comes from Git itself; the older wording is shown on the GitHub Docs page on non-fast-forward errors.

Pick the fix that fits

what you want
you want to
run
result
Bring their work in and push
git pull then git push
Pull merges the remote commits into yours. If the same lines changed, you will hit a merge conflict. Fix that here.
Look before you merge
git fetch then git log --oneline main..origin/main
Shows the commits you are missing, without touching your files.
Keep a straight history
git pull --rebase then git push
Replays your commits on top of theirs. Fine for commits only you have. Avoid on shared work.
Overwrite the remote on purpose
git push --force-with-lease
Only on a branch that is yours alone, and only if you are sure. It refuses if someone pushed since you last fetched. Plain --force does not check.

Check it worked

always

After git pull, run git status. It should say your branch is ahead by your commits. Then git push shows a line like main -> main without "rejected". If the pull stopped on a conflict, fix that first.

When it goes wrong

related messages
fatal: refusing to merge unrelated historiesThe two histories share no commitThis usually means a different repo was added as the remote. Check git remote -v first. See remote origin.
fatal: Authentication failedSign-in problem, not a history problemSee the authentication fix.

Questions people ask

What does failed to push some refs mean?

Git could not update the remote branch with your commits. Here the reason is the line above it: [rejected], because the remote has commits you do not.

What is the difference between fetch first and non-fast-forward?

Same cause. fetch first appears when your copy has not seen the remote commits. non-fast-forward appears after you fetched and your branch is behind.

Should I use git push --force?

Not as a first move. It replaces the remote branch with yours and can delete other people's commits. Pull first. If you must, use --force-with-lease on your own branch.

Does git pull lose my local changes?

No. It merges the remote commits with your committed work. Uncommitted edits can block it, so commit or stash them first.

Git, Visually · Parts 1 to 3 · English