Recover local deleted git branches

If you want to delete local branches that were merged, type the following command

git branch --no-color --merged | command grep -vE "^(\*|\s*(master|develop|dev)\s*$)" | command xargs -n 1 git branch -d
If you use oh-my-zsh type gdba which is an alias for the above command

The output of the command will be like this:

Deleted branch branch-1 (was f72899d).
Deleted branch branch-2 (was 07486d4).
Deleted branch brnach-3 (was 5fc02d4).
Deleted branch branch-4 (was 5203df6).

The syntax is:

Deleted branch <your-branch> (was <sha>)

Recover the branch

To recover the branch you have to create it from the sha id:

git checkout -b <your-branch> <sha>


git checkout -b branch-1 f72899d