How to restore deleted git branch
Public
31 Dec 10:34

Short and working solution to restore deleted git branch. If you remember branch name you’re half way to success.

1. First find sha of the commit you want to checkout to

git reflog

# it'll return something like
# c518a26 (HEAD -> fixes, origin/fixes) HEAD@{0}: commit (merge): Conflicts resolved
# 821eb31 HEAD@{1}: checkout: moving from master to fixes
# eccb1e4 (origin/master, master) HEAD@{2}: checkout: moving from fixes to master
# eccb1e4 (origin/master, master) HEAD@{3}: checkout: moving from master to fixes
# eccb1e4 (origin/master, master) HEAD@{4}: checkout: moving from fixes to master
# c431f5c HEAD@{5}: checkout: moving from master to fixes
# eccb1e4 (origin/master, master) HEAD@{6}: checkout: moving from fixes to master
# eccb1e4 (origin/master, master) HEAD@{7}: checkout: moving from master to fixes
# eccb1e4 (origin/master, master) HEAD@{8}: pull origin master: Fast-forward
# c431f5c HEAD@{9}: checkout: moving from fixes to master
# 821eb31 HEAD@{10}: commit: My fixes, probably to be dropped

2. Checkout to certain commit in your branch

git co -b <<branch>> <<sha>>

# in my example it was:

git co -b fixes 821eb31

Use it. You’ll thank me later!

Comments

Empty! You must sign in to add comments.