Skip to main content

Sign in

Save your progress and access it from any device.

Or with email

Don't have an account?

Privacy policy

failed to push some refs How to fix this Git error

Your push was rejected because the remote branch has commits you don't have locally. This is one of the most common Git errors, especially when working in a team. Here is how to fix it safely.

Error explained

What this error means

When you see error: failed to push some refs to 'origin', Git is telling you that the remote branch has moved ahead of your local branch. Someone else pushed commits, or you rewrote history locally, and now the two branches have diverged.

Git refuses to push because doing so would overwrite commits on the remote that your local branch does not contain. This is a safety mechanism to prevent data loss.

The fix is straightforward: pull the remote changes into your local branch first, then push again. In most cases, this takes a single command.

Why it happens

Most common

Someone else pushed first

A teammate pushed new commits to the same branch while you were working. Your local branch is now behind the remote. This is the most frequent cause in team environments and is completely normal in collaborative workflows.

After rewrite

You rebased locally

You ran git rebase on commits that were already pushed. Rebase rewrites commit hashes, so Git sees your local branch as diverged from the remote even though the content is similar. This requires a force push to resolve.

After amend

You amended a pushed commit

Running git commit --amend on the last commit changes its hash. If that commit was already pushed, the remote and local histories no longer match. You will need --force-with-lease to update the remote.

How to fix it

Three approaches depending on your situation. Start with pull --rebase, which works in most cases and keeps history clean.

Pull with rebase (recommended)

Pull with merge

Force push (after rewrite only)

How to prevent it

Pull before you push

Make it a habit to run git pull --rebase before pushing, especially on shared branches. This ensures your local branch includes all remote commits before you try to upload yours.

Use feature branches

Work on a dedicated branch instead of committing directly to main. Feature branches reduce conflicts because fewer people push to the same branch simultaneously. Merge via pull requests when ready.

Fetch often to stay up to date

Run git fetch origin periodically throughout the day. This downloads remote changes without modifying your working directory, so you can see if the remote has moved ahead before you try to push.

A

GitQuest is created by Anaïs (nouvelle fenêtre), web developer and head of education, specializing in tech training and digital accessibility.

Questions about this error

Master Git push and pull without the headaches

GitQuest teaches you collaborative Git workflows through realistic scenarios. No more mysterious push errors.

Start learning Git