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

Drill — Botched-Rebase Recovery

Recover from a force-pushed rebase that dropped commits, using reflog + ORIG_HEAD, and repair the remote ref. Optional interleaved drill after the rebase lessons.

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

The brief

Engineer rebases a 6-commit feature branch onto updated main, force-pushes with --force, then discovers two dropped commits and a rewritten teammate commit — shared branch, colleagues already pulled.

Starter state (seed script)

mkdir rebase-recovery && cd rebase-recovery
git init && git switch -c main
echo "base" > shared.txt && git add . && git commit -m "main base"
git switch -c feature/analytics
for i in 1 2 3 4 5 6; do echo "feat $i" >> feature.txt; git add . && git commit -m "feat $i"; done
git switch main && echo "main update" >> shared.txt && git commit -am "main update"
git switch feature/analytics
git rebase main --force-rebase   # the bad rebase
git push --force origin feature/analytics   # to a local bare "remote"

Your task

  1. Diagnose what the rebase destroyed: git reflog + git reflog feature/analytics + ORIG_HEAD — identify the dropped/rewritten commits.
  2. Restore the branch to its pre-rebase state: git reset --hard <pre-rebase-sha> (from reflog), verify git diff against the original.
  3. Repair the remote ref with --force-with-lease and explain lease semantics.
  4. Write POSTMORTEM.md: what --force destroyed, the recovery path, why --force-with-lease + branch-per-author prevents recurrence.

Deliverables

  • Repo URL with recovered branch (submission notes).
  • POSTMORTEM.md + terminal transcript upload.

Submission contract: paste the repo URL into submission notes and upload POSTMORTEM.md + transcript. Reviewer checks the branch is restored to pre-rebase state and the remote ref was repaired with --force-with-lease.

100-pt rubric

  • Diagnose dropped/rewritten commits via reflog + ORIG_HEAD (25)
  • Restore branch to pre-rebase state, verify diff (25)
  • Repair remote with --force-with-lease, explain lease semantics (20)
  • POSTMORTEM distinguishes rebase vs merge conflict recovery (15)
  • Prevention checklist (15)

Track your learning progressFree

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