The Real Mistake, Caught Immediately
remote: error: direct commit ... rejected on protected branch master
This block's own real hook, still active — the exact real signal that these commits need a proper branch first.
Recovery Path A: Branch, Reset, Push
git branch feature/waffle-toppings
git reset --hard origin/master
git switch feature/waffle-toppings
git push -u origin feature/waffle-toppings
The real, accidental commits are saved onto a real branch before master is genuinely reset back to the clean, real remote state.
Recovery Path B: Cherry-pick, Reset
git switch -c feature/pancake-toppings origin/master
git cherry-pick <accidental-commit>
git switch master
git reset --hard origin/master
A real, equivalent copy of the accidental commit lands on a fresh branch built directly from the real remote — master itself never even carries the mistake locally for long.
Certificate 2's last lesson: the classic real mistake every developer eventually makes — committing directly to master, having simply forgotten to branch first. This block's own real, genuine branch-protection hook (installed back in 2.5.4) catches it immediately: the push is rejected outright, the exact real signal that something needs fixing before anything reaches the team.
Two real, genuinely different recovery paths exist. The first time: save the accidental commits to a real branch, reset master back, push the branch. The second time, a separate mistake: cherry-pick the one accidental commit onto a fresh branch built from the real remote, then reset master back. Both are real, both work, both land through the same reviewed process this whole block has used throughout.
git branch <name> (without switching)
Creates a real, new branch pointer at the current commit without moving HEAD — confirmed directly in this lab: exactly what preserves the accidental commits before master is genuinely reset back.
git cherry-pick <commit>
Applies one real, specific commit's changes onto the current branch as a genuinely new commit. Confirmed directly in this lab: an equivalent, real copy of the accidental commit lands cleanly on a fresh branch built from the real remote.
Takeaways
- A protected-branch hook rejecting a direct push is the real, honest signal to fix the mistake before it reaches the team
- Recovery Path A: git branch (save the commits) → git reset --hard origin/master (clean master) → push the new branch
- Recovery Path B: git switch -c <branch> origin/master → git cherry-pick <commit> → reset master back
- Both real recoveries land the fix through the exact same reviewed PR process this whole block has used throughout