Fix Git "Updates Were Rejected" on Push
Your push bounces because the remote moved on without you. Here is how to catch up cleanly, when to rebase versus merge, and when a force-push is actually safe.
Key takeaways
- Git rejects a push as non-fast-forward or fetch first when the remote branch has commits your local branch lacks.
- Run git fetch, then git pull --rebase (or a merge pull), resolve any conflicts, and push again.
- Force-push only branches you own, and then with git push --force-with-lease, never plain --force.
On this page
Git rejects a push when the remote branch has commits yours doesn't, because pushing would erase them. Fix it with git pull --rebase origin main (or a merge pull), resolve any conflicts, then git push. Force-push only branches you own, and only with git push --force-with-lease.
Verified against
Git 2.56.0, against the git-scm.com git-push and git-pull reference pages and GitHub's protected branches docs. Checked October 2026.
The error comes in two flavors. When someone pushed since your last fetch:
$ git push origin main
! [rejected] main -> main (fetch first)
error: failed to push some refs to 'github.com:acme/api.git'
hint: Updates were rejected because the remote contains work that you do not
hint: have locally. This is usually caused by another repository pushing to
hint: the same ref.
And when you have fetched, but not integrated:
! [rejected] main -> main (non-fast-forward)
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart.
Nothing is broken. Git is refusing to overwrite commits you have never seen. The fix is to bring them into your history first.
What "non-fast-forward" actually means
The git-push docs state the rule: by default only fast-forward updates are allowed, meaning the remote branch tip must be an ancestor of what you push. If your branch is the remote plus a few commits on top, Git moves the pointer forward in a straight line.
Once someone else pushes, the histories split. Your branch and origin/main share an ancestor, but each has commits the other lacks, so there is no straight line and Git stops. Same root cause for every variant: the remote moved, you didn't.
Step one: look before you pull
$ git fetch origin
$ git status -sb
## main...origin/main [ahead 2, behind 1]
$ git log --oneline --graph HEAD origin/main
fetch updates your view of the remote without touching your branch. "ahead 2, behind 1" is the divergence in numbers, and the graph shows both lines meeting at the shared ancestor.
Merge vs rebase: pick your history
Rebase replays your local commits on top of the remote ones, as if you had written them after everyone else:
$ git pull --rebase origin main
Successfully rebased and updated refs/heads/main.
$ git push origin main
Straight-line history, no merge bubble. This is our default for "I have two small commits and someone pushed meanwhile." Rebasing rewrites your local commit hashes, so never rebase commits you have already shared. On unpushed work it is safe.
Merge ties the two lines together with a merge commit:
$ git pull --no-rebase origin main
$ git push origin main
It records honestly that two people worked in parallel, at the cost of Merge branch 'main' of ... commits that carry no information. Our rebase vs merge post goes deeper on when each is right.
A bare git pull on diverged branches does neither. The git-pull docs say --ff-only is the default when no reconciliation method is configured, so it fails and asks you to choose. Set your choice once:
$ git config --global pull.rebase true
When the pull hits a conflict
Either approach stops when both sides touched the same lines. Edit the files to remove the <<<<<<< markers, then:
# merge pull
$ git add path/to/file
$ git commit
# rebase pull
$ git add path/to/file
$ git rebase --continue
Rebase stops at each conflicting commit, so you may resolve and continue several times. git rebase --abort puts you back exactly where you started, which is why we don't fear rebase. Fixing a Git merge conflict covers the resolution itself. Once the pull is clean, git push fast-forwards.
The force-push case
Sometimes your version should win: you cleaned up a feature branch with an interactive rebase or amended a commit, and pulling would re-merge the junk you deleted. That is the legitimate home of force-push, and plain --force is still wrong:
$ git push --force origin my-feature # overwrites whatever is there
$ git push --force-with-lease origin my-feature # only if the remote is where you last saw it
Plain --force deletes a teammate's commit pushed ten minutes ago without telling you. --force-with-lease overwrites only if the remote ref still matches your remote-tracking branch; if someone pushed, it is rejected as (stale info), which is the feature.
The git-push docs warn that the lease "interact[s] very badly with anything that implicitly runs git fetch", like an IDE fetching in the background: your tracking ref moves and the lease passes without you seeing the new commits. Add --force-if-includes, which refuses unless the remote tip is reachable from your local reflog, meaning you actually integrated it:
$ git push --force-with-lease --force-if-includes origin my-feature
$ git config --global push.useForceIfIncludes true # make it the default
Our rule without exception: force-push only branches that are yours. Never main, never a shared release branch.
Every rejection string, and its fix
| Error text | Cause | Fix |
|---|---|---|
! [rejected] main -> main (fetch first) | Remote has commits you have not fetched | git pull --rebase, then push |
! [rejected] main -> main (non-fast-forward) | You fetched but your branch is behind | git pull --rebase or git rebase origin/main, then push |
! [rejected] my-feature -> my-feature (stale info) | --force-with-lease saw an unexpected remote tip | git fetch, inspect git log HEAD..origin/my-feature, integrate, retry |
fatal: Need to specify how to reconcile divergent branches. | Bare git pull on diverged branches | Rerun with --rebase or --no-rebase, or set pull.rebase |
remote: error: GH006: Protected branch update failed for refs/heads/main. | GitHub branch protection | Open a pull request; never force |
! [remote rejected] main -> main (pre-receive hook declined) | Server-side hook or protection (GitLab, Bitbucket, self-hosted) | Read the remote: lines above it; usually protection or a policy check |
Protected branches
GitHub's docs say it plainly: "By default, GitHub blocks force pushes on all protected branches." Even --force-with-lease bounces. If the branch also requires linear history, merge commits are refused too, so a merge pull followed by a direct push fails while a rebase pull succeeds. Most protected branches go further and require a pull request, in which case the fix is to push a feature branch and merge through review. If you find yourself wanting to force-push main, stop. That urge is the bug.
Where this breaks
Rebase-then-push assumes the remote history is correct and yours is the one to adapt. If the remote was force-pushed by someone else (a rewritten shared branch), pulling with rebase can replay commits that were deliberately removed; check git log origin/main against what you expect before integrating. Large monorepos with a busy main can also race you: the remote moves again between your pull and push. Merge queues exist for that, and on such repos the right move is a PR, not a faster git pull. For the other Git failures that land mid-sprint, our Git troubleshooting guide covers the rest.
Questions people ask
Why does Git say "the tip of your current branch is behind its remote counterpart"?
Your local branch is missing commits that exist on the remote, usually because someone pushed after your last pull. Git refuses the push so it does not discard their work. Run git pull --rebase to replay your commits on top of theirs, resolve any conflicts with git add and git rebase --continue, then run git push again. No force is needed.
Is it safe to use git push --force to fix a rejected push?
Only on a branch nobody else pushes to, and even then use git push --force-with-lease --force-if-includes, which refuses to overwrite commits you have not seen or integrated. On main or any shared branch, never force: integrate the remote work and push normally. On GitHub, protected branches block force pushes by default anyway, so the attempt simply fails.
Should I use git pull or git pull --rebase?
Use git pull --rebase for small unpushed local commits; you get linear history with no merge noise, and branches that require linear history accept it. Use git pull --no-rebase when you want the parallel work recorded as a merge, or when your commits are already shared, since rebasing rewrites their hashes. Set the default once with git config --global pull.rebase true.
The call we'd make
Nine times out of ten this error means one thing: git fetch, git pull --rebase, resolve any conflict, push. Straight-line history, no drama. Reach for a merge pull only when you want the fork recorded or the branch policy forbids rewriting. Force-push lives on your own branches and nowhere else, and when you do it, it is --force-with-lease --force-if-includes every time, so Git can still stop you before you overwrite someone's afternoon.
Sources
Cite this article
Kiril Urbonas (2026). Fix Git "Updates Were Rejected" on Push. DevOpsNess. Updated 2026-10-31. https://www.devopsness.com/blog/fix-git-push-rejected
[Fix Git "Updates Were Rejected" on Push](https://www.devopsness.com/blog/fix-git-push-rejected) (Kiril Urbonas, DevOpsNess, updated 2026-10-31)
More from DevOps
Explore more articles in this category
kaniko CVE-2026-105769: Lookalike ACR Hosts Get Your Azure Token. Rebuild on v1.25.20
A FROM line pointing at a host like x.azurecr.io.attacker.com is enough to make kaniko hand the build's Entra ID token to that host. Which kaniko forks and images are affected, how to find Azure identities in your build pods, and what to rotate.
Sign Container Images With Cosign: Keyless GitHub Actions Workflow, SBOM and In-Cluster Checks
One workflow that builds, signs keylessly with GitHub OIDC, attaches an SBOM and SLSA provenance, plus the Kyverno policy that refuses anything unsigned. Copy it, change three names, ship it.
GitLab CVE-2026-110264: A Second CVSS 10 RCE in Nine Days. Patch to 19.5.1
An unauthenticated regex-compiler RCE reaching back to GitLab 7.0, no workaround, and backports on older branches that fix only the critical bug. The exact version per branch and the commands to get there.
You might have missed
Evergreen posts worth revisiting.