PlainError

git push: error: failed to push some refs (rejected, non-fast-forward)

Updated 2026-11-23 · 6 fixes · expanded guide with sources · how we write fixes

TL;DRgit push was rejected as non-fast-forward because the remote branch has commits your local branch doesn't have. Git refuses to overwrite them. Bring those commits in first (git pull --rebase or git pull), fix any conflicts, then push again. Don't force-push a shared branch.

Most likely cause: Someone else, or you on another machine, pushed to the same branch since you last pulled

Try first: See what is different (git fetch origin && git log --oneline --left-right HEAD...origin/main)

Likely causes

  1. Someone else, or you on another machine, pushed to the same branch since you last pulledmost likely
  2. You rewrote local history (rebase, amend, reset) on a branch that was already pushedpossible
  3. The remote was changed through the web UI (a merged pull request, an edited README, an initial commit when creating the repo)possible

Why this happens

A push is a fast-forward when the remote branch's latest commit is already in your branch's history, so Git only has to add your new commits on top. If the remote has commits you don't have, accepting your push would drop them, so Git rejects it as non-fast-forward.

The fix is always to combine the two histories first. Rebase gives a straight line; merge keeps both lines and adds a merge commit. Both are safe; force-pushing is the only option that discards work.

Common situations

How to fix it

Safest first: SafeChanges settingsDangerous
  1. See what is differentSafe

    Fetch the remote without changing your files, then list commits on each side.

    git fetch origin && git log --oneline --left-right HEAD...origin/main
  2. Rebase your commits on top of the remoteChanges settings

    Replays your local commits after the remote ones, keeping history linear. Replace main with your branch name.

    git pull --rebase origin main
  3. Or merge insteadChanges settings

    If your team prefers merge commits, or you're unsure about rebasing, a normal pull creates a merge commit.

    git pull origin main
  4. Resolve any conflictsChanges settings

    Edit the conflicted files, then mark them resolved. During a rebase continue with git rebase --continue; to back out, use git rebase --abort.

    git add <file> && git rebase --continue
  5. Push againChanges settings

    Once your branch contains the remote commits, the push is a fast-forward and goes through.

    git push origin main
  6. Only if you rewrote your own branch: force with leaseDangerous

    If the branch is yours alone and you intentionally amended or rebased it, push with --force-with-lease, which refuses if someone else pushed in the meantime.

    git push --force-with-lease origin my-branch

    ⚠ Make a backup branch first (git branch backup-my-branch). Never force-push main or any shared branch; it can delete other people's commits from the remote.

If that didn't fix it

If the push is still rejected after pulling, check the full message: 'protected branch' or 'pre-receive hook declined' are server rules, not history problems. Related: [fatal: refusing to merge unrelated histories](/code/fatal-refusing-to-merge-unrelated-histories).

When to see a technician

If a rebase goes wrong, run git rebase --abort to get back to where you started, or git reflog to find your previous commit, and ask a teammate before forcing anything.

Questions people ask

Should I use git push --force?
Not on shared branches. Use git pull --rebase or a merge. On a branch only you use, prefer --force-with-lease over --force.
Rebase or merge?
Follow your team's convention. Rebase keeps history linear but rewrites your unpushed commits; merge never rewrites but adds a merge commit. Either fixes this error.

Sources

Did this fix it? Report a problem

Related errors

All Coding errors →