Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,364,737
Community Members
 
Community Events
168
Community Groups

Cannot find / checkout remote branch after delete

I (a long time ago) deleted a branch via the BitBucket Cloud Web page / app.

A remote team member (junior / new developer-in-training) was on leave - but now is back and has been committing and pushing code changes to the deleted branch.

(They do not have the skills / code  / project oversight to do the merging. 
I did think that I would just get them to switch to the new branch and merge in all their changes into it. But this is beyond their current skillset) 

So I need to be able to checkout the remote branch to my machine, so that I can do the required merge(s) to get the new "main" brain up to date with his changes.

I have the remote path and the SHA of the last commit he pushed and tried the following;

get fetch
git checkout -b origin/theDeletedPath <the commitSHA>

But I get an error that I can't resolve:

fatal: reference is not a tree: <the commitSHA>

The branch I want to recover does not appear in BitBucket Cloud (I have ensured that I am looking for ALL branches - not just active.

I have tried;
git branch -a -v

The latest commit/push to the deleted branch (unsurprisingly) does NOT appear in the commits for the repo, either.

I'd really appreciate any thoughts you might have.

Thanks!

1 answer

0 votes
Ben Atlassian Team Aug 30, 2022

Hey Gavin,

If the remote branch has been deleted - you will not be able to push to the remote branch from your local.

I would suggest attempting to locate the local branch on the user's machine by running the git branch command to list only local branches.

Once this has been performed, you can then run a git checkout command to switch to the local branch and then push this to remote - once you push, this will create the origin/theDeletedPath linkage that you are expecting to see (if the branch name is different, you can rename the branch with git branch -m old_name new_name before pushing)

Unfortunately - if this data is lost and there is no local backup, our Cloud backups include the last 7 days of data in warm storage and any older is not easily recoverable.

Hope this helps.

Cheers!

- Ben (Bitbucket Cloud Support)

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Site Admin
TAGS

Atlassian Community Events