Recover from an Incident
Classify the incident
After release, Alice creates a private branch for a maintenance note, commits it, and accidentally moves the branch back to main in a clean disposable clone. The new note is missing from the working snapshot, but its commit may still exist. The production tag and remote main were not changed. Record the expected and observed state before repair. This is a synthetic incident, not a suggestion to reset a real branch.
Locate and preserve evidence
Inspect status, refs and local reflog. In the fixture, the previous HEAD entry is the intended commit, but in real work select the candidate by inspecting evidence, not by assuming an index. Verify its message, parent and changed file before creating a new rescue branch. Keep any unrelated local files backed up independently. Do not prune or expire reflogs during investigation.
git status --shortgit reflog show HEADgit show --stat "HEAD@{1}"Recover without rewriting shared history
After verifying the fixture candidate, create rescue-maintenance at that commit and inspect its contents. Leave main and the release tag unchanged. The recovery branch restores a name for committed work without touching working files. The lab verifies the recovered note, original remote main and tag, and the unchanged release digest. A real missing object may need an authorized backup instead; never promise recovery for unrecorded bytes.
git branch rescue-maintenance "HEAD@{1}"git show rescue-maintenance:maintenance.txtDocument prevention
Write a short incident record containing symptoms, preserved evidence, cause, action, verification and remaining limitations. Propose small commits, explicit branch checks and independent backups. Do not treat reflog retention as guaranteed backup. The rescue branch remains private until its content passes normal review. Explain why a forced push would not be an appropriate response here.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Recover from an Incident — knowledge check
Apply evidence-based professional repository maintainership.
What should precede repair?
Where might a previous private tip be found?
Why inspect a candidate before rescue?
What does a rescue branch do?
What must remain unchanged in this incident?