Reinstating deleted Bitbucket repositories from a local copy

  

Platform Notice: Cloud, Server, and Data Center - This article applies equally to all platforms.

Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

  

Summary

This article describes a scenario where a repository which was hosted in Bitbucket Cloud was deleted, and needs to be reinstated for any reason.

Requirements

There are a couple of requirements that you need to meet before you proceed with the steps to recover the repository:

  1. To reinstate the repository, please make sure that you have a local copy of the repository that has most or all branches from the deleted repositories.
    You can check if it was a local copy of the previously deleted repository by running the following command:

    git remote -v

    Make sure that the URL that shows up matches the URL of the previously deleted repository.

    In addition to that, you can check if your local copy of the repository has multiple branches by running the following command on it:

    git branch -a
  2. You need to have the ability to create new repositories under the affected workspace (admin or write access to the target workspace);
  3. You need to have either an SSH key or App password added to your personal settings, so you can authenticate against the target workspace.

Steps to recover the repository

  1. Create a new repository on the desired workspace;

  2. Once the repository is created, on the source tab of the new repository, click on the "Clone" button. You should see a pop up similar to the one below:
    1. If you have an SSH key added to your personal settings, please select SSH on the dropdown in the top right corner of the pop-up;
    2. If you have an App password added to your personal settings, please select HTTPS on the dropdown in the top right of the pop-up.

  3. From the pop up above, copy everything after the "git clone" section. You should have either git@bitbucket.org/:<workspaceID>/<repoSlug>.git  or https://bitbucket.org/<workspaceID>/<repoSlug>.git  on your clipboard.

  4. On the local copy of the repository, run the following command, using what was copied on step 2 as <remoteURL> :

    git remote set-url origin <remoteURL>
  5. Run the following command to push to Bitbucket:

    git push --force --all
  6. Navigate to the repository on Bitbucket. Make sure to validate if the branches and commits match the local copy of the repository: 
    1. To check the commits, run the following command on the local copy of the repository, and compare it to the commits section of the repository on Bitbucket Cloud.

      git log
    2. To check the branches, run the following command on the local copy of the repository, and compare it to the branches section of the repository in Bitbucket Cloud.

      git branch -a



Last modified on Mar 10, 2023

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.