Restore Deleted Git Branch

This solution works only if too much time hasn't been passed since the branch was deleted.

If you have accidently deleted a branch in your Git repository, you will see something like this in your terminal:

Syntax of Branch deleted message in terminal:


Deleted branch <branch-name> (was ).

Example: Deleted branch test (was 5756a8c06).

To restore the above deleted branch, use the command as follows:

Syntax

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

Example: git checkout -b test 5756a8c06

If you do not know the <sha> of the deleted branch, then you can use the Reflog tool of Git to find the <sha> from the local records of sha.

Example

git reflog

To restore the branch, you can use the following command:

Syntax

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

Example: git checkout -b test 5756a8c06