prosseek prosseek -4 years ago 129
Git Question

Can I recover branch after its deletion in git?

If I run

git branch -d XYZ
to delete branch 'XYZ', is there a way to recover the branch. In other words, is there a way to go back as if I didn't run the branch delete command?

Answer Source

Yes, you should be able to do git reflog and find the SHA1 for the commit at the tip of your deleted branch, then just git checkout [sha]. And once you're at that commit, you can just git checkout -b [branchname] to recreate the branch from there.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download