0 votes
17 views

Can you recover a deleted branch in Git?

in Technology by (191k points)

1 Answer

0 votes

 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.

by (191k points)

Related questions

0 votes
1 answer 27 views
27 views asked Jan 8 in Technology by JackTerrance (191k points)
0 votes
1 answer 20 views
20 views asked Jan 7 in Technology by JackTerrance (191k points)
0 votes
1 answer 23 views
23 views asked Jan 7 in Technology by JackTerrance (191k points)
0 votes
1 answer 23 views
0 votes
1 answer 38 views
0 votes
1 answer 27 views
0 votes
1 answer 32 views
32 views asked Jan 8 in Technology by JackTerrance (191k points)
0 votes
1 answer 21 views
0 votes
1 answer 26 views
0 votes
1 answer 84 views
84 views asked Dec 10, 2020 in Technology by JackTerrance (191k points)
0 votes
1 answer 30 views
0 votes
1 answer 22 views
0 votes
1 answer 23 views
0 votes
1 answer 18 views
18 views asked Jan 7 in Technology by JackTerrance (191k points)
0 votes
1 answer 23 views
0 votes
1 answer 24 views
0 votes
1 answer 32 views
0 votes
1 answer 37 views
37 views asked Jan 8 in Technology by JackTerrance (191k points)
0 votes
1 answer 20 views
20 views asked Nov 4, 2020 in Technology by JackTerrance (191k points)
0 votes
1 answer 28 views
0 votes
1 answer 24 views
0 votes
1 answer 22 views
0 votes
1 answer 47 views
...