Recover a branch I deleted
I ran git branch -D and the branch had work that was not merged.
The problem
I ran git branch -D and the branch had work that was not merged.
How the practice repository looked before
## main
1f118d4 First
The fix
1f118d4 HEAD@{0}: checkout: moving from feature to main
7a7441f HEAD@{1}: commit: Work on feature
1f118d4 HEAD@{2}: checkout: moving from main to feature
1f118d4 HEAD@{3}: commit (initial): FirstCheck the result
feature * main
7a7441f Work on feature 1f118d4 First
Why this works
Deleting a branch only removes its name. The commits stay in the repository until they are cleaned up. The reflog shows where HEAD was just before you left that branch, and git branch <name> <place> makes a new name for it.
If this is not quite your case
If the reflog does not show the branch work, git fsck --lost-found can list commits that no branch points at. After you recover the branch, push it again if it was on a remote; deleting a local branch does not delete the remote one.
This is an independent guide. It is not connected with the Git project, GitHub, GitLab or any company named here. Every command below was run on 14 November 2026 with the real program (git version 2.56.0.windows.4) in a new empty practice repository; the output shown is what it printed. Facts about options were read in the official Git documentation on 14 November 2026.