THE GITHTML FIELD GUIDE
Recover a deleted local Git branch from its commit
Deleting a local branch removes its name, not necessarily its commits immediately. Search remaining references and local reflogs for the former tip, inspect the candidate commit, and create a new branch at that verified identifier. Recovery is time-sensitive because unreachable objects and reflog entries are not kept forever, and uncommitted work needs separate protection.
Look for another reference before guessing
The deleted branch may still have a remote counterpart, a tag, or commits reachable from another branch. Inspect those first. If the branch was merged, its work may already be present in the integration history even though its name is gone. Recreating the name is different from restoring missing code.
If no obvious reference remains, inspect the HEAD reflog for times you checked out or committed on the branch. A deleted branch’s own reflog may no longer be available, so do not rely exclusively on its old name. Avoid garbage collection, pruning, or cleanup while searching, because those operations can reduce recovery options for unreachable objects.
Verify a candidate tip before recreating
The placeholder COMMIT must be replaced by a candidate found in evidence, not a remembered short hash. Inspect its recent history and representative files. Create a new recovery branch name first to avoid replacing a name that may already have been reused. Branch creation alone does not change the working tree.
- Compare the recovered tip with the task’s expected final changes. A checkout entry may identify an earlier point than the branch’s last useful commit.
- If the branch existed only on another computer, that computer’s reflog or an authorized remote may have evidence your local clone never received.
git branch --all
git reflog --date=iso
git show --stat COMMIT
git log --oneline -5 COMMIT
git branch recovery/deleted-topic COMMITPreserve recovery evidence and choose the next action
Once the branch exists, verify its identifier and keep it until the recovered work is reviewed. Decide separately whether to rename it, merge it, or publish it. A local branch recovery does not automatically recreate a deleted remote branch, and recreating a remote reference can have collaboration consequences.
If no candidate can be found, be explicit about the limits: the clone may never have had the commit, or local retention may have expired. Do not promise that reflog can recover every deleted branch. A reliable outcome names the exact recovered tip and the evidence connecting it to the lost work, rather than declaring success merely because a branch with the old spelling exists again.
- If a remote counterpart survives, compare its tip with the candidate from your HEAD reflog. The remote may be missing the final local commit, or it may include later work from someone else. Record which version matches the lost task before assigning a new recovery name.
- A reused branch name can now identify unrelated work. Avoid replacing it during recovery; create a distinct recovery branch at the verified old commit instead. Compare the two histories by commit identifiers, so recreating a familiar label does not silently displace someone’s current branch.
Sources and further reading
AI-assisted writing with source-linked guidance and illustrative examples. Read our editorial approach or report a correction.