Skip to content
Commitpedia
Log in Join & edit

Fix: error: failed to push some refs to …

Git refused your push, usually because the remote branch has commits you do not have yet. Bring them in, combine them with your work, and push again. Force only when you really mean to.

Edit history of Fix: error: failed to push some refs to …: 1 recorded edit
Edit history · 1 edit
Type
Article
Edits
1
Editors
1
First issued
15 Oct 2026
Last edit
15 Oct 2026
Reading
2 min

This is a summary line. The real reason is in the lines just above it, so read the whole output. The most common version looks like this:

 ! [rejected]        main -> main (fetch first)
error: failed to push some refs to 'github.com:owner/repo.git'
hint: Updates were rejected because the remote contains work that you do not
hint: have locally.

You will also see (non-fast-forward) instead of (fetch first) when Git already knows about the remote commits. Both mean the same thing: the remote branch moved on since your last pull, and pushing now would throw those commits away, so Git refuses.

Fix: integrate, then push

git pull --rebase
git push

--rebase replays your local commits on top of what is on the remote, which keeps history straight. If you prefer a merge commit, use git pull --no-rebase. If you run plain git pull and get Need to specify how to reconcile divergent branches, pick one of these flags, or set a default once with git config --global pull.rebase false (merge) or true (rebase).

If the pull stops with a conflict, fix the marked files, git add them, and run git rebase --continue (or git commit after a merge). Then push.

You rewrote your own branch on purpose

After git commit --amend, git rebase, or git reset on a commit you had already pushed, the remote has the old version and rejects the new one. Pulling here would bring the old commits back. If the branch is yours alone, overwrite it safely:

git push --force-with-lease

This only succeeds if the remote still points where you last fetched it; if someone pushed in the meantime you get stale info instead of silently deleting their work. Avoid plain --force, and never force-push a shared branch such as main.

Other causes with the same last line

  • error: src refspec main does not match any: there is no local branch with that name. Either you have not made a commit yet, or your branch is called something else. Check with git branch, and push the name it shows.
  • A line starting with remote: that mentions a protected branch or a rule: the repository does not allow direct pushes to that branch. Push to a new branch and open a pull request.
  • remote: lines about authentication or permission: your credentials are wrong or you lack write access. See the git remote -v URL and your SSH key or token.
  • pre-receive hook declined or a message about file size: the server rejected the content itself. The text after remote: says why.

Avoid it next time

Run git pull before you start work and again before you push, and keep your work on a branch of its own rather than on a shared main.

See also

  • 0041 Fix: CONFLICT (content): Merge conflict in … Two branches changed the same lines and Git cannot choose for you. Open the file, keep the right text, remove the markers,… Intermediate · Fix · Any system Article Branching & rebasing · Common errors 15 Oct 2026
  • 0042 Fix: fatal: refusing to merge unrelated histories Your local repository and the remote do not share a single commit, usually because both were started separately. Allow the one-time merge,… Intermediate · Fix · Any system Article Common errors 15 Oct 2026

History

Every saved edit is kept. The plot on the sleeve draws one line per edit. Open any edit to see exactly what changed.

  1. commitpedia-admin +2,626 chars

Report a problem

Something wrong, unsafe or copied? Tell the editors.
What is wrong?