Someone force-pushed over main and 12 commits vanished. How do you recover?
IntermediateProductionRecovery and incident handling
Answer
Find the old tip: from a teammate's clone or CI runner (git reflog, origin/main@{1}), GitHub's push events API or the Activity view on the branch, or the PR refs. Then restore with a force push, which needs a temporary ruleset bypass.
gh api repos/ORG/REPO/activity -f ref=refs/heads/main -f activity_type=force_push
git push --force-with-lease=main:<bad-sha> origin <good-sha>:main
More on Recovery and incident handling
After recovery, what do you change so a force-push to main cannot happen again?AdvancedA bad migration commit was deployed. Walk through your response in the first 15 minutes.IntermediateHow do you recover a deleted repository or branch on GitHub?IntermediateHow do you find who or what pushed a specific commit to a protected branch?AdvancedCI is red on main after a merge. What is your policy?IntermediateA teammate rebased a shared branch and now everyone has duplicate commits. How do you repair it?Advanced