Recovering a Deleted Branch

Four real commits. One genuinely deleted branch. Recovered in full.

feature/spice-blends has four real, genuine commits — never merged into master. git branch -D force-deletes it anyway, the way a real "I don't need this anymore" click sometimes turns out to be a mistake.\n\nDeleting a branch only ever removes the real pointer — a small file naming a commit hash. The four real commits themselves are untouched, sitting in the real object database exactly as before, simply unreachable from any current ref. HEAD's own reflog remembers switching away from that branch, which is exactly enough to find its way back.

Deleting Only Removes the Pointer

git branch -D feature/spice-blends

This removes one small real file — the branch pointer. The four real commits it named are still sitting in the object database, genuinely untouched.

Finding Its Real Last Position

git reflog | grep -A1 "moving from feature/spice-blends to master"

The checkout line itself shows the destination's hash (master's), not the deleted branch's — the entry one step further back, the real last commit made on that branch, is the one that actually matters here.

Bringing It Back

git branch recovered-spice-blends <hash>
git log --oneline recovered-spice-blends -4

A real, ordinary branch pointer, recreated at the exact right commit — all four real commits, back in full.

git branch <name> <hash>

Creates a real, ordinary branch pointer at a specific commit — exactly the same operation as creating any new branch, just aimed at a hash recovered from reflog instead of the current HEAD. Confirmed directly in this lab: the recreated branch's real history is byte-identical to the deleted one.

🗑️ Delete It (On Purpose, For Now)

A real, unmerged, four-commit branch — force-deleted.

cd ~/team-recipes && git branch -a | grep spice
cd ~/team-recipes && git branch -D feature/spice-blends
cd ~/team-recipes && git branch -a | grep spice

student@lab:~$ cd ~/team-recipes && git branch -a | grep spice feature/spice-blends old/spice-experiments student@lab:~$ cd ~/team-recipes && git branch -D feature/spice-blends Deleted branch feature/spice-blends (was 744b578). student@lab:~$ cd ~/team-recipes && git branch -a | grep spice old/spice-experiments

🔎 Find Its Exact Real Last Position

HEAD's own reflog remembers switching away from it.

cd ~/team-recipes && git reflog | grep -A1 "moving from feature/spice-blends to master"

student@lab:~$ cd ~/team-recipes && git reflog | grep -A1 "moving from feature/spice-blends to master" 3d4111f HEAD@{0}: checkout: moving from feature/spice-blends to master 744b578 HEAD@{1}: commit: Add five spice blend

🌿 Recover It in Full

A real, ordinary branch, recreated at the exact right commit.

cd ~/team-recipes && git branch recovered-spice-blends $(git reflog | grep -A1 "moving from feature/spice-blends to master" | tail -1 | awk '{print $1}')
cd ~/team-recipes && git log --oneline recovered-spice-blends -4

student@lab:~$ cd ~/team-recipes && git branch recovered-spice-blends $(git reflog | grep -A1 "moving from feature/spice-blends to master" | tail -1 | awk '{print $1}') student@lab:~$ cd ~/team-recipes && git log --oneline recovered-spice-blends -4 744b578 (recovered-spice-blends) Add five spice blend 413290f Add zaatar blend 040703d Add garam masala blend 2e24180 Add Cajun spice blend

Lab 3.4.2 complete. A real, unmerged branch, deleted and fully recovered:\n\n\n git branch -D : ✅ pointer removed\n git reflog : ✅ exact real last commit found\n git branch <name> <hash>: ✅ all 4 commits recovered\n

Enable JavaScript to run the live terminal and track your progress.