Last Updated on March 8, 2024

Each of us certainly had a situation where we first got rid of some data, because we did not need it, but after some time we realized that we wanted to recover this data. It could be anything, an old note, a photo, or it can be an entire repository. Then what? We would like to recover this data somehow! Unfortunately, this is not always possible, so we should remember to regularly back up our data. Today we will talk about repositories and how we can recover them using two popular services – GitHub and Bitbucket.

Let’s delete GitHub repository

Before we figure out how to restore a repository, let’s first delete it. If you want to know more about removal, you should check out the article here: How to delete a repository in GitHub But for now we don’t need to know the details. Let me show you a simple scenario in GitHub.

To remove a GitHub repository you need to open the settings of that one and scroll down. There you will find the section called “Danger Zone” which contains a few options. One of them is “Delete this repository”. So let’s do that and remove it.

How to delete a GitHub repository

Now let’s do the same with Bitbucket and then jump to the restoring topic. The story is similar. You need to open the repo, that you want to remove, move to the “Repository settings” section and then in the upper right corner click on the button “Manage repository”. It is a select field with two options: “Transfer repository” or “Delete repository”. Select the second one and then you will see this:

Transfer or delete GitHub repository

All right, we’ve done it. But be aware of the consequences. Deleting the repository is a permanent action and will remove all of its settings, comments, and so on. So be careful with this operation! 

Visual learner? Then, don’t read but watch our GitProtect Academy video to find out how to restore a deleted repository in GitHub and Bitbucket (Psst, don’t forget to subscribe!)

How to restore a deleted repository

What does “restore” actually mean? We’ve already established that deletion is permanent, so you might ask yourself – “What’s this all about? How can I recover something that is permanently deleted? ”. Well, the answer is not that simple and it depends on what hosting service we use. For sure we will lose all information not directly related to our files, such as permissions, comments, labels etc. Let’s check how it works thoroughly.

Get free trial

GitHub allows us to recover the repository within 90 days of its deletion. But there are a few things we need to know about this, especially if our repository was part of the fork network. What is that? The official documentation will explain to us:

A fork network consists of a parent repository, the repository’s forks, and forks of the repository’s forks.

Complicated? It may sound like that, but it is not. Now the important thing, which is why this definition is important. If our repo was part of such a network then it cannot be restored! Well, unless every other repository in the network would be deleted or detached, but that scenario is highly improbable and often it’s not up to us.

In the documentation, we can find a mention that if we want to restore such a repository, if we cannot do it ourselves, we can contact GitHub Support on this matter, so let’s not lose hope. However, I do not recommend this type of solution because this way we lose control.  And you cannot be 100% sure that the support could help you. We are dependent on others, and that is never a good thing when it comes to accessing our data.

Okay, but let’s move on to the most important one, which is the answer to the question that led us here. To restore the deleted GitHub repository, we need to open the settings, go to the “Repositories” tab, then we will see something like this:

restoring deleted repository

All of our deleted repositories will be listed under the “Deleted repositories” tab. Of course, all that were deleted no more than 90 days ago. Note the message on the blue background, GitHub informs us directly that the repositories belonging to fork network cannot be restored as I described above. Another important thing is the information about the time interval between deletion and restoration. You can test yourself, create a new repository, delete it, and then go straight to restoring. Spoiler alert – you will fail. But that shouldn’t be a problem, because if you want to restore the deleted repository, most likely it was removed much earlier than an hour ago.


How secure are your repos and metadata? Don’t push luck – secure your code with the first professional GitHub, Bitbucket, and GitLab backup.


Recovering deleted repository in Bitbucket

Now let’s check how it works in Bitbucket. At support.attlasian.com you can find a thread titled: “Can I restore a deleted repository or commits?”

What’s the official answer?

No. You are responsible for backing up your repository. Creating a regular backup can protect your repository from accidental, user-caused, data loss.

End of story. This is a thread from Dec 2 2020 and nothing has changed since then. On the other hand, we can also find another thread on the same page, titled: Restore a deleted repository for Bitbucket Server”

This thread describes two ways to recover a deleted repository, but it is not really recovery, understood in the same way as for example in GitHub. They require us to have a third-party Bitbucket backup, which is already the first difference because it’s not Bitbucket that cares about it, but ourselves. The “recovery” process itself is actually creating a new repo from a backup or a local version of the repository – if there is one at all. Either way, we need to create a new, empty repository in Bitbucket, then set the appropriate origin address and perform a push operation that will restore the repository to us from the backup.

Conclusions – restoring a deleted repository is not easy

First of all, everything depends on the platform we use, but even the very friendly GitHub has some limitations related to it. Having our own backups and our own recovery procedures gives us peace of mind because we can keep them for as long as we want and restore them from any point in time to many destinations (the same or new repository, account, cross-over to another git hosting service or to your local machine). They also allow us to simplify the recovery procedures, which will certainly make our work easier. Although remember we can always run into some problems if our procedures are not up to date. So think over your decision a few times before you decide to delete the repository. Or at least have DevOps backup in place then.

Comments are closed.

You may also like