Recover from Non-Fast-Forward Rejection
Understand the rejection
Alice and Bob each make a different commit on main from the same base. Alice pushes first. Bob’s push is rejected because replacing remote main with Bob’s tip would omit Alice’s commit. Do not force push to bypass the safeguard.
git push origin maingit fetch origingit log --oneline --left-right main...origin/mainThe first command fails in this specific lab scenario. Continue with fetch and inspect; both sides contain one unique commit.
Integrate and retry
A fast-forward-only pull refuses divergent history. In this lab the changes are in different files, so an explicit merge can preserve both. If a real merge conflicts, resolve and test or abort as taught in Chapter 7. A new concurrent push can cause another rejection.
git pull --ff-only origin maingit merge --no-edit origin/maingit status --shortgit push origin mainThe pull intentionally fails; run the remaining commands separately only after confirming divergence. The merge has two parents, both files survive, and the final push succeeds in the isolated lab.
Practice and check
Use the Chapter 10 lab guide. Before each command predict which local or remote reference changes, then compare the observed result. Diagnose rejection without blindly forcing a push.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Recover from Non-Fast-Forward Rejection — knowledge check
Check understanding of remote repository behavior.
Why does Bob’s divergent push fail?
What is the safe first action?
What does successful divergent merge preserve?
What if integration produces conflicts?
Why can a retry be rejected again?