Git: Recover deleted (remote) branch

  1. find out commit id

    git reflog

  2. recover local branch you deleted by mistake

    git branch <NEED-RECOVER-BRANCH-NAME> commitId

  3. push need-recover-branch-name again if you deleted remote branch too before

    git push origin <NEED-RECOVER-BRANCH-NAME>


I'm not an expert. But you can try

git fsck --full --no-reflogs | grep commit

to find the HEAD commit of deleted branch and get them back.


just two commands save my life

1. This will list down all previous HEADs

git reflog

2. This will revert the HEAD to commit that you deleted.

git reset --hard <your deleted commit>
ex. git reset --hard b4b2c02

Tags:

Git

Github