Recover a deleted Git branch
Safe: nothing is lost
Short answer
Find the branch's last commit with git reflog (or in the Deleted branch … (was abc1234) message), then git branch <name> <commit>.
The commands, one by one
- 1
git reflogLists everywhere
HEADhas been, newest first. Look for the last commit you made on the deleted branch: here it'sHEAD@{1}, one move ago, before you switched back tomain. - 2
git branch gift-cards HEAD@{1}Creates the branch again, pointing at that commit. All its commits are back.
For your own repository: If you still have the Deleted branch gift-cards (was 1a2b3c4) message, git branch gift-cards 1a2b3c4 works too. Reflog entries expire after about 90 days.