The "Oops, I Committed to Main" Recovery
Two real accidents, two genuinely different real recoveries — both landing the normal, reviewed way.
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.\n\nTwo 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.
The Real Mistake, Caught Immediately
git push
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.
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.
😅 The First Real Mistake
Two real commits, forgotten to be branched — and the block's own hook catches it.
cd ~/team-recipes && git switch mastercd ~/team-recipes && printf 'Waffle Toppings\n\nMaple syrup, whipped cream, fresh berries.\n' > waffle-toppings.mdcd ~/team-recipes && git add waffle-toppings.mdcd ~/team-recipes && git commit -m 'Add waffle toppings guide'cd ~/team-recipes && printf '\nCinnamon sugar, sliced bananas.\n' >> waffle-toppings.mdcd ~/team-recipes && git add waffle-toppings.mdcd ~/team-recipes && git commit -m 'Add more topping ideas'cd ~/team-recipes && git pushstudent@lab:~$ cd ~/team-recipes && git switch master Switched to branch 'master' Your branch is up to date with 'origin/master'. student@lab:~$ cd ~/team-recipes && printf 'Waffle Toppings\n\nMaple syrup, whipped cream, fresh berries.\n' > waffle-toppings.md student@lab:~$ cd ~/team-recipes && git add waffle-toppings.md student@lab:~$ cd ~/team-recipes && git commit -m 'Add waffle toppings guide' [master 43ad024] Add waffle toppings guide 1 file changed, 3 insertions(+) create mode 100644 waffle-toppings.md student@lab:~$ cd ~/team-recipes && printf '\nCinnamon sugar, sliced bananas.\n' >> waffle-toppings.md student@lab:~$ cd ~/team-recipes && git add waffle-toppings.md student@lab:~$ cd ~/team-recipes && git commit -m 'Add more topping ideas' [master be9b2d1] Add more topping ideas 1 file changed, 2 insertions(+) student@lab:~$ cd ~/team-recipes && git push Enumerating objects: 7, done. Counting objects: 100% (7/7), done. Compressing objects: 100% (6/6), done. Writing objects: 100% (6/6), 613 bytes | 51.00 KiB/s, done. Total 6 (delta 3), reused 0 (delta 0), pack-reused 0 remote: error: direct commit be9b2d1e16a26bf70cfe299326622fe95360ef49 rejected on protected branch master remote: master only accepts merge commits from a reviewed pull request To ../recipes-origin.git ! [remote rejected] master -> master (pre-receive hook declined) error: failed to push some refs to '../recipes-origin.git'
🌿 Recovery Path A: Branch, Reset, Push
Save the real accidental commits to a proper branch, then reset master back to clean.
cd ~/team-recipes && git branch feature/waffle-toppingscd ~/team-recipes && git reset --hard origin/mastercd ~/team-recipes && git switch feature/waffle-toppingscd ~/team-recipes && git push -u origin feature/waffle-toppingscd ~/team-recipes && git switch mastercd ~/team-recipes && git merge --no-ff feature/waffle-toppings -m 'Merge pull request: waffle toppings'cd ~/team-recipes && git pushcd ~/team-recipes && git branch -d feature/waffle-toppingscd ~/team-recipes && git push origin --delete feature/waffle-toppingsstudent@lab:~$ cd ~/team-recipes && git branch feature/waffle-toppings student@lab:~$ cd ~/team-recipes && git reset --hard origin/master HEAD is now at bb33753 Merge pull request: revert protein shakes student@lab:~$ cd ~/team-recipes && git switch feature/waffle-toppings Switched to branch 'feature/waffle-toppings' student@lab:~$ cd ~/team-recipes && git push -u origin feature/waffle-toppings Enumerating objects: 7, done. Counting objects: 100% (7/7), done. Compressing objects: 100% (6/6), done. Writing objects: 100% (6/6), 613 bytes | 76.00 KiB/s, done. Total 6 (delta 3), reused 0 (delta 0), pack-reused 0 To ../recipes-origin.git * [new branch] feature/waffle-toppings -> feature/waffle-toppings branch 'feature/waffle-toppings' set up to track 'origin/feature/waffle-toppings'. student@lab:~$ cd ~/team-recipes && git switch master Switched to branch 'master' Your branch is up to date with 'origin/master'. student@lab:~$ cd ~/team-recipes && git merge --no-ff feature/waffle-toppings -m 'Merge pull request: waffle toppings' Merge made by the 'ort' strategy. waffle-toppings.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 waffle-toppings.md student@lab:~$ cd ~/team-recipes && git push Enumerating objects: 1, done. Counting objects: 100% (1/1), done. Writing objects: 100% (1/1), 229 bytes | 114.00 KiB/s, done. Total 1 (delta 0), reused 0 (delta 0), pack-reused 0 To ../recipes-origin.git bb33753..ec1d5b7 master -> master student@lab:~$ cd ~/team-recipes && git branch -d feature/waffle-toppings Deleted branch feature/waffle-toppings (was be9b2d1). student@lab:~$ cd ~/team-recipes && git push origin --delete feature/waffle-toppings To ../recipes-origin.git - [deleted] feature/waffle-toppings
😅 A Second, Separate Real Mistake
It happens again — a different real accident, calling for a different real recovery.
cd ~/team-recipes && printf 'Pancake Toppings\n\nMaple syrup, butter, fresh fruit.\n' > pancake-toppings.mdcd ~/team-recipes && git add pancake-toppings.mdcd ~/team-recipes && git commit -m 'Add pancake toppings guide'student@lab:~$ cd ~/team-recipes && printf 'Pancake Toppings\n\nMaple syrup, butter, fresh fruit.\n' > pancake-toppings.md student@lab:~$ cd ~/team-recipes && git add pancake-toppings.md student@lab:~$ cd ~/team-recipes && git commit -m 'Add pancake toppings guide' [master 11ee21e] Add pancake toppings guide 1 file changed, 3 insertions(+) create mode 100644 pancake-toppings.md
🍒 Recovery Path B: Cherry-pick, Reset
A fresh branch built from the real remote, the accidental commit cherry-picked onto it.
cd ~/team-recipes && git switch -c feature/pancake-toppings origin/mastercd ~/team-recipes && git cherry-pick mastercd ~/team-recipes && git push -u origin feature/pancake-toppingscd ~/team-recipes && git switch mastercd ~/team-recipes && git reset --hard origin/mastercd ~/team-recipes && git merge --no-ff feature/pancake-toppings -m 'Merge pull request: pancake toppings'cd ~/team-recipes && git pushcd ~/team-recipes && git branch -d feature/pancake-toppingscd ~/team-recipes && git push origin --delete feature/pancake-toppingsstudent@lab:~$ cd ~/team-recipes && git switch -c feature/pancake-toppings origin/master branch 'feature/pancake-toppings' set up to track 'origin/master'. Switched to a new branch 'feature/pancake-toppings' student@lab:~$ cd ~/team-recipes && git cherry-pick master [feature/pancake-toppings f0ce38a] Add pancake toppings guide Date: Mon Aug 24 20:00:09 2026 +0000 1 file changed, 3 insertions(+) create mode 100644 pancake-toppings.md student@lab:~$ cd ~/team-recipes && git push -u origin feature/pancake-toppings Enumerating objects: 4, done. Counting objects: 100% (4/4), done. Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 338 bytes | 112.00 KiB/s, done. Total 3 (delta 1), reused 0 (delta 0), pack-reused 0 To ../recipes-origin.git * [new branch] feature/pancake-toppings -> feature/pancake-toppings branch 'feature/pancake-toppings' set up to track 'origin/feature/pancake-toppings'. student@lab:~$ cd ~/team-recipes && git switch master Switched to branch 'master' Your branch is ahead of 'origin/master' by 1 commit. (use "git push" to publish your local commits) student@lab:~$ cd ~/team-recipes && git reset --hard origin/master HEAD is now at ec1d5b7 Merge pull request: waffle toppings student@lab:~$ cd ~/team-recipes && git merge --no-ff feature/pancake-toppings -m 'Merge pull request: pancake toppings' Merge made by the 'ort' strategy. pancake-toppings.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 pancake-toppings.md student@lab:~$ cd ~/team-recipes && git push Enumerating objects: 1, done. Counting objects: 100% (1/1), done. Writing objects: 100% (1/1), 231 bytes | 77.00 KiB/s, done. Total 1 (delta 0), reused 0 (delta 0), pack-reused 0 To ../recipes-origin.git ec1d5b7..b2968b5 master -> master student@lab:~$ cd ~/team-recipes && git branch -d feature/pancake-toppings Deleted branch feature/pancake-toppings (was f0ce38a). student@lab:~$ cd ~/team-recipes && git push origin --delete feature/pancake-toppings To ../recipes-origin.git - [deleted] feature/pancake-toppings
Lab 2.6.4 complete — Block 2.6 complete — Certificate 2 complete. Two real accidents, two genuine recoveries:\n\n\n First mistake caught by real hook : ✅ confirmed\n Recovery Path A (branch+reset) : ✅ waffle toppings\n Second mistake caught again : ✅ confirmed\n Recovery Path B (cherry-pick+reset): ✅ pancake toppings\n
Enable JavaScript to run the live terminal and track your progress.