Recovering a Deleted Branch

Sam tries a cover-image placeholder on a branch, commits it, switches back, and deletes the branch with -D, which unlike -d deletes unmerged work without asking:

Deleting an unmerged branch, then bringing it backShell
git switch -q -c experiment/covers
# Edit public/index.html: a cover placeholder for each book
git commit -qam "Show a cover placeholder for each book"
git switch -q main
git branch -D experiment/covers
git reflog -3
git branch experiment/covers HEAD@{1}
git log --oneline -1 experiment/covers
Output
Deleted branch experiment/covers (was c7ba56f).
035e659 HEAD@{0}: checkout: moving from experiment/covers to main
c7ba56f HEAD@{1}: commit: Show a cover placeholder for each book
035e659 HEAD@{2}: checkout: moving from main to experiment/covers
c7ba56f Show a cover placeholder for each book

The branch's own reflog was deleted with it, but HEAD's remembers the commit it made there, and git branch recreated the name. git branch -D even prints the old tip, "was c7ba56f", which is often all you need. For a branch you never checked out, the commit appears in no reflog; git fsck (git fsck) finds it. A branch that was pushed is easier still: git switch experiment/covers recreates it from origin/experiment/covers.