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

Cannot find / checkout remote branch after delete

Gavin Baumanis
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!
August 9, 2022

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
Atlassian Team members are employees working across the company in a wide variety of roles.
August 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
Product Admin
TAGS
AUG Leaders

Atlassian Community Events