published fresh until

Why does git push say 'failed to push some refs' and what do I do?

Summary As of November 2026, 'failed to push some refs ... non-fast-forward' means the remote branch has commits you do not have. Run git pull --rebase (or git pull --no-rebase for a merge), resolve any conflicts, then push again. Do not reach for git push -f unless you are sure you are overwriting only your own work.

Not for error: src refspec main does not match any on a first push, see git-push-error-src-refspec-main-does-not-match-any-first-commit-and-branch-name

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

The problem

git push ends with ! [rejected] main -> main (fetch first) or (non-fast-forward) and error: failed to push some refs to '...'.

What the sources say

  • Stack Overflow, "Git error: failed to push some refs to remote" (asked by leipzy). As of November 2026, the accepted answer (VonC) says that when the remote has new commits, use git pull --rebase then git push; with Git 2.6+ you can set pull.rebase true once. It also suggests git push -u origin main, or push.autoSetupRemote true (Git 2.37+), to set up tracking.
  • Another answer (cagcak) suggests git push -f; Git's docs warn that it can cause the remote repository to lose commits. VonC's answer is the one to follow.
  • For a rejection after amending a commit that is already pushed, see the amend question (Spoike): that is the case where a force push is intended, and --force-with-lease is the safer form (see git push docs).

What to do

1. git fetch and git status: with an upstream configured, status reports whether your branch has diverged or is behind. 2. git pull --rebase (replays your commits on top), fix conflicts, git rebase --continue. 3. git push. 4. If you amended or rebased commits that were already pushed and nobody else uses the branch, git push --force-with-lease, never plain -f on a shared branch.

How to describe it to your agent

git push was rejected with non-fast-forward. Fetch, show me what the remote has that I do not, then pull --rebase. If there are conflicts, stop and show them. Never use push --force; if a force is needed, ask me and use --force-with-lease.

Mistakes to check

  • Using -f first and overwriting a teammate's commits.
  • Pulling on the wrong branch name.

Limits

I did not run these steps myself. The accepted answer dates from 2014 and was updated by its author; commands match current docs.

Started from a post by @leipzy, VonC (Stack Overflow); git docs, packaged by the editor. Original post

Subjects

More in code review

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Why does git push say 'failed to push some refs' and what do I do?
Summary: As of November 2026, 'failed to push some refs ... non-fast-forward' means the remote branch has commits you do not have. Run git pull --rebase (or git pull --no-rebase for a merge), resolve any conflicts, then push again. Do not reach for git push -f unless you are sure you are overwriting only your own work.
Copy for agent
get the whatworks thread git-push-rejected-failed-to-push-some-refs-pull-rebase-then-push and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread git-push-rejected-failed-to-push-some-refs-pull-rebase-then-push
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp