The commit history was gone. Lines of work, weeks of changes, erased by a single command: git reset --hard. Silence on the screen, except for the blinking cursor. No warnings. No way back—unless you know exactly what to do next.
A Git reset incident is one of the fastest ways to lose code in active development. It can happen when force-resetting a branch to a previous commit, rolling back after a rebase gone wrong, or cleaning up local changes before pushing. In all cases, the damage is immediate. Your incident response determines whether you recover or escalate the loss.
Step 1: Stop and Assess
Do nothing else until you confirm what was lost. Check git reflog to see all movements in your repository, even after a hard reset. The reflog keeps a chronological list of commits your HEAD has pointed to. Find the commit hash before the reset and note it down.
Step 2: Recover Locally if Possible
Use git reset --hard <commit-hash> to restore the branch to the state before the reset. If the commits were orphaned and garbage collected, you will need more advanced recovery, such as scanning the .git/objects directory for loose commits.
Step 3: Coordinate with Remote
If your branch is connected to a remote, compare local recovery options with the remote branch state. Use git fetch and git log origin/<branch> to confirm whether upstream still has the missing commits. Avoid pushing until you know which branch contains the authoritative history.
Step 4: Document and Automate
Log the entire incident, including commands run and timestamps. Reflog entries can become your forensic record. Automate protections using hooks or CI rules that prevent destructive resets on shared branches. Consider integrating automated snapshot systems that run outside Git for even faster recovery.
Preventing Future Git Reset Incidents
Enforce branch protection rules. Require pull requests for merges and block force pushes on critical branches. Configure git config --global advice.resetHard false if you want Git to warn before destructive operations. Regular backups of .git directories for active repositories can keep a safety net ready.
Fast Incident Response Saves Code
Every second after a git reset --hard matters. Knowing the recovery path—from reflog navigation to branch restoration—turns a potential disaster into a solvable problem. Keep these steps documented, test them, and be ready to apply them instantly.
Want to practice and see real incident response workflows in action? Spin it up live with hoop.dev in minutes.