Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

recover accidentally deleted branches in bitbucket

Makarand Karmarkar October 28, 2019

I have deleted all REMOTE branches except master and my current tracked branch using

$ git push GRSC359 --delete n0312285/ErrorBodyjs-1551204972468

where "GRSC359" is the remote name and "n0312285/ErrorBodyjs-1551204972468" is the branch name. 

I want to know that apart from other users pushing their code back to the repository, is there any other way to recover the remote branches? Like is there a backward push from the Bamboo from current deployed code back to the Bitbucket.? Any help would be greatly appreciated.

Thanks

 

2 answers

1 accepted

0 votes
Answer accepted
Makarand Karmarkar November 19, 2019

A team member found the answer by checking the fetch history to be just before the deletion and then pushing individual remote branches back to the origin. There are other approaches based on what level of deletion you are in as found here and here
I am going to accept my answer as written above since it worked for me
"This is when/if they have fetched entire repository they do have the option to switch to the remote branch and push that code. The only drawback to this is that it will push the version at the 'fetch' point in time and not have the changes that were made after the fetch time. For most old branches it is perfectly fine. This will restore the repository branch structure and individual branch code but with a slight different history of 'refs'."

1 vote
Jimmy Seddon
Community Champion
October 29, 2019

Hi @Makarand Karmarkar,

Unfortunately, there is no way to undo something pushed to the remote without using another user's copy who has not pulled the latest changes from the remote.

Bamboo for the most part should be deleting what it has cloned after the build has run successfully so I don't believe it will have a copy of the information you are looking to retrieve.

Do you have any other users that are able to re-push a number of the branches you deleted?  

It will take a significant amount of work, but with help from the rest of the development team you should be able to reconstruct all the branches.

Makarand Karmarkar October 29, 2019

Thanks @Jimmy Seddon for the reply. With help from other development team members I was able to push the most recent branches.

I don't know if I am allowed to do answer my own question but I did find the solution within my team.

This is when/if they have fetched entire repository they do have the option to switch to the remote branch and push that code. The only drawback to this is that it will push the version at the 'fetch' point in time and not have the changes that were made after the fetch time. For most old branches it is perfectly fine. This will restore the repository branch structure and individual branch code but with a slight different history of 'refs'.

Jimmy Seddon
Community Champion
October 30, 2019

I'm glad you were able to find a solution to this.  I have some experience with these types of mistakes myself so I know how stressful they can be.

-Jimmy

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events