There are times when things go wrong. We started a project, but we want to forget about it and remove all traces of it. Or we just want to move our project to another service and get rid of it completely from the previous place. There are various reasons, but this is not the topic for today – today I will tell you how we can delete our Git repositories and what it entails.

What is a repository?

First, let’s find out what a repository is. According to Wikipedia: A software repository (…) is a storage location for software packages (…) typically managed by source control or repository managers. But let’s focus on Git. Git is a distributed version control system, an engine that allows us to create and manage our archives. So Git itself is a tool, not a service. You can download Git to your PC and start using it to create and manage your own, local repo.

On top of that, there are some popular hosting services that work in repositories as a service model. The most popular are GitHub, GitLab, and Bitbucket. So what’s the difference? Should I use Git or GitHub? This is a wrong question as GitHub uses the Git engine internally, it just offers more than that. Most of the hosting services, apart from the basic functionality, mainly offer access control, web applications with access to our code, graphical interfaces facilitating the performance of certain operations, and much more.

Using Git is also possible without hosting services like GitHub, but then we must have our own server if we want to use such a repository for teamwork. We can, but what for? A better way is to use existing services.

Get free trial

Let’s delete GitHub repository

As I mentioned at the very beginning, there can be various reasons for removing repositories. Consider a simple case when I create myself a new Git repository on my laptop. A few simple steps and everything is ready. In the system path where I created our project, a directory called .git is created. Without delving into its contents, if we want to remove the local files, this directory should be removed. That’s it. Done! Our local Git repository is eradicated.

Okay, but the above situation is very rare, more likely to happen while learning rather than actually working with Git. We mostly use different services like GitHub, so our repository is physically distributed. Removing the local .git directory will only remove our local copy, while the remote repository will still exist.

So how to delete a repository in GitHub? First, you need to be an organization owner or have admin permissions for the repository. It is possible also to block this option to the admins and only the owner would be able to do that. The next step is to log in to our Github account and open the settings of the repository that we want to remove. There we will find the “Delete this repository” option, and to confirm the action, we will have to manually enter its name. Simple? Simple. The entire process is also well documented in the GitHub documentation.

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

However, you must know the consequences of such an action – this operation will permanently delete our repository and all of its settings. Moreover, this action cannot be undone! If there are any forks, they will also be removed, as long as the repository being deleted was not public.

How is it actually with these forks?

It is true that deleting a private repo will remove all its private forks. But we can avoid this thanks to the repository access change mechanism. Such a tool is provided by GitHub. And now it gets interesting because if we turn our private repo, let’s call it MyProject, into public, all of its forks will remain private. What’s more, when we remove MyProject – which is now public – every private fork will turn into a standalone private repository.

Can we restore a repository somehow

On the one hand, GitHub clearly informs us that the removal operation cannot be undone. And this is true, although such a repository can be recreated later. But be aware, as this will not restore any release attachments, permissions, or labels. For 90 days after deletion, GitHub allows you to restore the repository, but there are many limitations. First of all, you can only restore archives owned by your user account. Other restrictions apply to forks. This is a bit more complicated limitation, let me quote an excerpt from the GitHub documentation:

“A deleted repository can be restored within 90 days, unless the repository was part of a fork network that is not currently empty. A fork network consists of a parent repository, the repository’s forks, and forks of the repository’s forks. If your repository was part of a fork network, it cannot be restored unless every other repository in the network is deleted or has been detached from the network.”

As seen above, GitHub can recover deleted repository, but not in all circumstances, so we have to be careful and think five times about every decision to remove the repository. It’s best to have your own backups, then the GitHub restrictions do not apply to us and we can restore our repo at any time and without restrictions.

Unconscious removal of the repository

It seems impossible, i.e. we can delete the .git directory locally, but it’s hard to accidentally wipe out the remote repository. As you already know, you need to confirm several times that you want to do it. However, it may happen that someone takes over our account and launches an attack aimed at removing our repositories. Having control over the account, we can easily run a malicious script that will delete repositories in a simple and quick way. I have not heard of such a situation, usually, the hacker prefers to encrypt the data and demand a ransom (you can read about that here), however, it is theoretically possible.

To summarize – removing our repository from GitHub is fairly easy. We just need to meet a few conditions, that is, first of all, to have the right to do so. In addition, we must be aware of the consequences of such action, especially if our repository has been forked or we have changed permissions from public to private or vice versa.

Comments are closed.

You may also like