non-fast-forward 🌿 Git

Git: ! [rejected] … (fetch first) — error: failed to push some refs

The remote branch has commits you don’t have locally, so Git refuses to overwrite them. Pull (merge or rebase) first, then push.

Seen on: Git

Meaning

Your push would not be a fast-forward: someone (or you, from another machine or the GitHub web UI) pushed new commits. Git protects the remote from losing them.

Common causes

  • Teammate pushed to the same branch
  • You edited files on GitHub (e.g. README) after cloning
  • You rewrote local history (rebase/amend) on an already-pushed branch
  • Branch protection rejecting the push (different message: protected branch hook declined)

⚡ Quick fix

  1. git pull --rebase origin <branch> then git push
  2. Resolve conflicts if any, git rebase --continue
  3. Only if you intentionally rewrote history on your own branch: git push --force-with-lease

Detailed fix by platform

Git

  1. Typical sequence:
    bash
    git fetch origin
    git pull --rebase origin main
    # fix conflicts if prompted, then:
    git add . && git rebase --continue
    git push origin main
  2. Never --force on shared branches; --force-with-lease refuses if someone else pushed in the meantime.

How to diagnose

  1. Hint — Does the message say “fetch first” or “non-fast-forward”?
  2. Remote — git log origin/main.. vs git log ..origin/main
  3. Protection — Is the branch protected?

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.