Git & GitHub Mastery: Workflows & CI/CD
Back to Real-World Git Workflows

Drill — Detached-HEAD Rescue

Recover a commit made while HEAD was detached using reflog, then recreate the branch. Optional interleaved drill after the reflog lessons.

33 minutesAssignment
🎯 Free Guest Mode: You are learning for free. Sign in to save your completion progress and quiz answers.

The brief

On-call engineer checks out a release tag to reproduce a stakeholder's number, makes a "quick fix" commit while detached, then git switch main — the fix vanishes from all branches the night before a reporting deadline.

Starter state (seed script)

mkdir rescue-drill && cd rescue-drill
git init && git switch -c main
for i in 1 2 3 4 5; do echo "v$i" >> report.py; git add . && git commit -m "report v$i"; done
git tag v1.2
git checkout v1.2            # DETACHED HEAD
echo "fix off-by-one in totals" >> report.py
git add . && git commit -m "fix off-by-one in totals"   # orphan commit
git switch main              # the fix "vanishes"

Your task

  1. Confirm the fix is gone from every branch: git log --all --oneline shows no fix off-by-one.
  2. Find the orphan commit: git reflog → locate the commit: fix off-by-one in totals entry → note its SHA.
  3. Recreate the branch at that SHA: git switch -c fix/off-by-one <sha>.
  4. Verify the content: git log --oneline --graph shows the rescued commit on a named branch; cat report.py contains the fix.
  5. Write RESCUE.md: what detached HEAD means, how reflog located the orphan, the prevention rule (never commit detached; use git switch -c).

Deliverables

  • Repo URL (submission notes).
  • RESCUE.md file upload.

Submission contract: paste the repo URL into submission notes and upload RESCUE.md. Reviewer checks the rescued branch exists with the fix content, and the graph shows a clean topology.

100-pt rubric

  • Reproduce detachment + locate orphan via reflog (25)
  • Recreate branch at orphan SHA, verify content (25)
  • Explain detached-HEAD semantics correctly in RESCUE.md (20)
  • Graph shows clean topology (15)
  • Prevention rule stated (15)

Track your learning progressFree

Sign in or enroll free to mark this assignment as complete, save your progress, and earn certificates.