in Technology by

Can you recover a deleted branch in Git?

Please log in or register to answer this question.

1 Answer

0 votes
by

 Yes, you can. To recover a deleted branch, you should know the SHA off the top of your head. SHA or hash is a unique ID that Git creates with every operation.

When you delete a branch, you get the SHA displayed on the terminal:

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

You can use the below command to recover the deleted branch:

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

If you don’t know the SHA for the commit at the tip of your branch then you can first use the git reflog command to know the SHA value and then apply the above checkout command to restore your branch.

Related questions

0 votes
asked Feb 2, 2022 in Education by JackTerrance
0 votes
asked Dec 24, 2022 in Technology by JackTerrance
0 votes
asked Jan 7, 2021 in Technology by JackTerrance
...