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 →
- Git printed the tip SHA when you deleted:
Deleted branch x (was 3f9a1c2). Use it:git branch x 3f9a1c2. - Otherwise
git reflogand find the last commit on that branch. - 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.
More on Undoing Mistakes
You committed on `main` when you meant to be on a feature branch. Nothing is pushed. Fix it.BeginnerYou made a typo in your last commit message and have not pushed.BeginnerA bad commit is already on shared `main`. Others have pulled it. How do you undo it?IntermediateYou ran `git reset --hard` and lost uncommitted-then-committed work. Can you get it back?IntermediateYou need to revert a merge commit on `main`. `git revert` says "commit is a merge but no -m option was given".IntermediateAfter `git stash pop` you got conflicts. Is your stash lost?Intermediate