Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

restone branch

Mukhriddin
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 7, 2023

I unknowingly deleted the dev and feature/payment_service_module branches. Ed is not visible in both branches local and remote and none of his commits are visible. How can I restore them?

1 answer

0 votes
Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 8, 2023

Hello @Mukhriddin  and welcome to the Community!

The easiest way to restore a deleted branch is by looking at other clones of the repository in question (on your or your colleague's machines) to see if they have a backup of the branch.  If this is the case, it may be easier to push the branch up to Bitbucket from the other copy of the repository that still has the branch. 

However, if you don't have another clone that includes the deleted branch and if you have deleted the branch both locally and on the remote, you might still be able to recover it if you have the working copy of the repository where the branch was deleted. This is because we will need to find on the reflog of your local clone of the repository what was the last commit of that branch, so we can create a new branch pointing to that commit.

The following command can be used to find what was the last commit in the deleted branch. In this example, we are using branch development

git reflog  --no-abbrev | grep development

The output of the command should be similar to this : 

11bf4fd3d4e58285938e0fce801b2b216a5c0d7f4 HEAD@{0}: checkout: moving from development to master
773677e7173488c64410af59e0c3287a24c54326 HEAD@{1}: checkout: moving from master to development

In this example, the reference log shows the last two moves for the development branch.  The first line is checking out the branch master with the hash 1bf4fd3.  The second line is when the repository moved from master to development, so this is the hash we are looking for.

Once the hash is found,  you can use the checkout command to create a new branch pointing to that commit : 

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

and your branch should be recreated.

We also have the following article with additional scenarios you might want to try in order to restore the deleted branch : 

Thank you, @Mukhriddin !

Patrik S

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events