Interview Prep/Git & GitHub/Undoing Mistakes

You deleted a local branch with unmerged work by mistake.

BeginnerScenarioUndoing Mistakes
Answer

Situation read → Deleting a branch removes the pointer, not the commits.

What I'd do →

  1. Git printed the tip SHA when you deleted: Deleted branch x (was 3f9a1c2). Use it: git branch x 3f9a1c2.
  2. Otherwise git reflog and find the last commit on that branch.
  3. Or check if the remote still has it: git branch -r.

Why → Objects stay in the repo until garbage collection prunes them.

Interview tip → Recovery depends on acting before gc prunes, usually weeks away.

All Git & GitHub questions Roadmap: Git & GitHub

More on Undoing Mistakes