A git push rejected non-fast-forward error means the remote branch contains commits that your local branch does not have, so Git refuses to move the remote pointer in a way that would discard them. To fix it, fetch the remote work, combine it with yours using git pull --rebase (or a merge), and push again. Do not reach for a force push unless you are sure you want to overwrite someone else's commits.
The message looks scary, but it is a safety check, not a failure of your repository. It usually appears when a teammate pushed to the same branch after you last pulled.
A fast-forward push is one where the remote branch tip is an ancestor of the commit you are pushing. Git simply moves the branch pointer forward along your history. A non-fast-forward push happens when the two histories have diverged.
Your local D and the remote C both descend from B. If Git accepted your push, C would become unreachable and its work would be lost from the branch. So the server rejects it:
A similar message says fetch first. That variant appears when your clone has not yet downloaded the new remote commits at all, so Git cannot even tell how the histories relate. The fix is the same.
Before changing anything, look at what differs. Fetch updates your remote-tracking branches without touching your working files.
git status reports how far the branches have drifted, for example Your branch and 'origin/main' have diverged, and have 1 and 1 different commits each. The log graph shows exactly which commits are only local and which are only remote. To see what the remote added, run:
The first command lists commits you do not have. The three-dot diff shows the remote changes since the common ancestor, which is the part you are about to integrate.
Rebasing replays your local commits on top of the updated remote branch, which keeps history linear.
After the rebase, the history looks like this, with D' being your commit recreated on top of C:
Your push is now a fast-forward and succeeds. Note that D' has a new hash, because a commit's hash depends on its parent. That is fine as long as D was never pushed.
If the same lines changed on both sides, the rebase pauses.
git status to see the conflicted files.<<<<<<<, ======= and >>>>>>> markers, and keep the correct result.git add <file> for each resolved file.git rebase --continue.git push.If it goes badly, git rebase --abort returns you to the state before the pull.
If your team prefers merge commits, or the branch is shared and already published, merge the remote work in.
This creates a merge commit with two parents:
Merging never rewrites existing commits, which makes it the safer choice when other people have based work on your commits. The cost is a busier history. You can set your default once so plain git pull behaves consistently:
Since Git 2.27, a plain git pull warns when pull.rebase is not set, and since Git 2.33 the warning is stronger, so choosing explicitly saves you from surprises.
Sometimes you rewrote history on purpose, for example by rebasing or amending a commit on your own feature branch that you had already pushed. The remote then looks "ahead" in an unrelated way and a normal push is rejected. In that case, use the safer force option.
--force-with-lease only overwrites the remote branch if it still points to the commit you last fetched. If a teammate pushed in the meantime, the push fails instead of silently deleting their work. Plain --force has no such check.
| Command | Overwrites remote | Protects teammates' new commits |
|---|---|---|
git push | No | Yes |
git push --force-with-lease | Yes | Yes, if you fetched recently |
git push --force | Yes | No |
Never force push to shared branches such as main. Many teams enforce this with branch protection rules, which then produce a different rejection message ("protected branch hook declined") rather than non-fast-forward.
git pull --rebase (or git fetch and inspect) before you start work and before you push.main.git branch -vv.Yes. A pull only downloads and integrates remote commits. Your local commits are kept, either replayed on top (rebase) or joined by a merge commit. If conflicts appear, Git stops and lets you resolve them.
fetch first means your local clone has not seen the new remote commits yet. non-fast-forward means Git already knows the remote tip is not an ancestor of yours. Both are resolved by pulling and pushing again.
It will make the push succeed, but it discards the remote commits that you do not have. Use it only on your own branches after a deliberate history rewrite, and prefer --force-with-lease.
Someone probably pushed again between your pull and push. Pull once more and push right away. Also check that the push target is the branch you intended with git status and git branch -vv.
A non-fast-forward rejection means the remote branch has commits you lack. Fetch, inspect the difference, integrate with git pull --rebase or a merge, resolve any conflicts, and push again. Reserve --force-with-lease for deliberate rewrites of your own branches, and avoid force pushing to shared ones.