Gitflow
☢️Force Push Disaster RecoveryHard+750 XP
Workshop
Scenario reference

Force Push Disaster Recovery: the situation, step by step

The situation

Junior dev ran `git push --force` on main, wiping 6 commits. Production broken.

Your local still has old refs from last fetch. Reflog is the lifeline.

Hard · 5 steps · +750 XP

What you will practice

This scenario walks through 5 steps, in order:

  1. 01Check reflog
  2. 02Create recovery branch
  3. 03Reset main
  4. 04Force push corrected main
  5. 05Verify
Reveal the step-by-step commands

Try the terminal first — you learn more by doing. When you want to check yourself, here is the command for each step.

  1. 1. Check reflog
    git reflog
  2. 2. Create recovery branch
    git branch recovery HEAD@{1}
  3. 3. Reset main
    git reset --hard HEAD@{1}
  4. 4. Force push corrected main
    git push --force-with-lease origin main
  5. 5. Verify
    git log --oneline

Key takeaway

Enable branch protection. Require PRs. Disable force-push on main.