ShareYourGroupShareYourGroupError Explainer

Git: failed to push some refs (fetch first / non-fast-forward)

A plain-words explanation of this Git message: what it means, the usual causes, and the steps that fix it.

The messageerror: failed to push some refs to 'origin'

Make the error yourself

Run with git version 2.56.0.windows.4. This is the smallest example we could find that shows it.

Setup used before these commands (a practice folder with no data)
export GIT_AUTHOR_NAME=Asha GIT_AUTHOR_EMAIL=a@example.com GIT_COMMITTER_NAME=Asha GIT_COMMITTER_EMAIL=a@example.com
git init -q --bare -b main remote.git
git clone -q remote.git one
cd one
echo 1 > f.txt
git add f.txt
git commit -qm first
git push -q origin main
cd ..
git clone -q remote.git two
cd one
echo 2 >> f.txt
git commit -qam second
git push -q origin main
cd ../two
echo 3 > g.txt
git add g.txt
git commit -qm third
cd two

Commands

git push

Git prints (the real message)

To ./remote.git
 ! [rejected]        main -> main (fetch first)
error: failed to push some refs to './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.

Why it happens

Someone, maybe you on another computer, has already pushed new commits to the same branch on the server. Your local branch is missing them, so if the server accepted your push it would lose their work. Git refuses and tells you to fetch first. The words "non-fast-forward" or "fetch first" in the hint mean the same thing: your history and the server's history have diverged.

How to fix it

  1. Bring in the new commits: git pull. Git downloads them and merges (or rebases) them with your own.
  2. If a conflict appears, fix the conflicting files, git add them and finish the merge (see the page on merge conflicts).
  3. Run git push again.
  4. Do not use git push --force to get past this. It overwrites the other person's work on the server. If you really must replace the history, use --force-with-lease, which at least refuses when the server has changed again.

The corrected version

Commands

git pull --no-rebase --no-edit
git push

Git prints (the corrected version)

Merge made by the 'ort' strategy.
 f.txt | 1 +
 1 file changed, 1 insertion(+)
From ./remote
   0e234bb..6a8eac3  main       -> origin/main
To ./remote.git
   6a8eac3..5b6bf67  main -> main

How to avoid it

Pull before you start working, and before you push, especially when several people share a branch.

Questions

Should I use merge or rebase when I pull?

Merge keeps the true order of events; rebase makes a straight line. Both are fine. Pick one for the team and use it every time.

This is an independent guide. It is not connected with Python, Microsoft, Google, GitHub or the Git project. Product names belong to their owners. Examples were run on 13 November 2026 in a practice folder or a blank workbook; your version may word a message slightly differently.