Skip to content
Recovery

Rescue a deleted branch

Deleting a branch removes a name, not the work.

`git branch -D` deletes forty bytes. Every commit that branch pointed at is still in the object store, and the branch's own reflog still records where it was.

So the rescue is to create the branch again at the position the reflog remembers: `git branch <name> <name>@{0}`.

If even the reflog is gone, `git fsck` can list commits nothing points at — but only until a garbage collection removes them.

Commands in this lesson

git branch
List, create or delete the names that point at commits
git reflog
Show every position a ref has held, and what moved it there
git fsck
Check the object store, and report objects nothing points at
No account, no backend. Everything you do stays in this browser.liter8.sh