THE GITHTML FIELD GUIDE
Handle a non-fast-forward Git push rejection safely
A non-fast-forward rejection means the proposed push would not simply extend the remote branch’s current history. Fetch the remote, inspect commits unique to each side, and choose the project’s integration policy. Do not force-push just to remove the error: the rejected update may be protecting another contributor’s work.
Treat the rejection as useful protection
Someone may have pushed after your last fetch, or you may have rewritten local commits that were already published. Both can make the server’s branch tip no longer an ancestor of your proposed tip. The error does not tell you which history should win; it tells you that a straightforward update would not preserve the current remote line.
Confirm the remote and branch involved before integrating anything. A wrong destination can also produce confusing rejection messages. If you intended to push a new feature branch but targeted main, correct the destination rather than merging unrelated history into your feature merely to satisfy the mistaken push command.
Fetch and compare both sides
The example assumes the current local branch corresponds to origin/fix/retry. Replace that reference with the actual destination. A left-right log reveals unique commits on each side; read their patches as needed. Fetch updates local knowledge but does not itself decide how to combine the histories.
- If the remote has new legitimate commits, integrate them through the repository’s accepted merge or rebase workflow after preserving local changes.
- If you intentionally rewrote published history, coordinate with everyone using the branch before any replacement procedure; a rejection is not authorization to overwrite them.
git status --short --branch
git remote get-url --push origin
git fetch origin
git log --left-right --oneline HEAD...origin/fix/retry
git diff --stat HEAD origin/fix/retryRetry only after understanding the combined result
After integration, inspect history and run the relevant tests. A merge can be textually clean while combining incompatible behavior. Then retry the explicit normal push. If another contributor updated the branch again, repeat the inspection rather than escalating automatically to force. For protected branches, the correct route may be a pull request instead of direct updates. Keep the original local and remote commit identifiers in your troubleshooting note so the cause remains explainable after both references move.
The remote may also apply branch protection independently of ancestry. If the rejection names a policy requirement, follow that requirement rather than confusing a permission or review rule with a history-divergence problem.
- Read the remote-only commit messages and patches before choosing an integration method. For example, a teammate’s rename may require updating your newly added import even if Git reports no textual conflict. Successful ancestry integration and correct application behavior need separate verification in this case.
- If you believe the branch was merely behind, inspect whether the comparison actually shows commits unique to both sides. That finding disproves the simple behind-only explanation. Investigate an amended local commit, a different destination, or concurrent work before selecting the repository’s approved merge or rebase approach.
Sources and further reading
AI-assisted writing with source-linked guidance and illustrative examples. Read our editorial approach or report a correction.