Developers enjoy using repositories on GitHub as a way to showcase their side projects. However, they may need to improve their portfolio by deleting a repository—the result is a less cluttered profile. But how do you do it? Our guide will show you just that.
1. Sign In to Github
To start the process, you need to first head over to github.com. If you’re using it regularly, you may be able to skip this step (or run through it really fast with pre-saved login info). But in case you’re new to Github or don’t use it often, we’ll start at the beginning.
You want to click where it says Sign in on the loaded-up page like so:
You’ll be asked for your username or email address and your password, so fill these in and then click the green Sign in button:
2. Find Your Repositories Library
On the next page, we need to go over to our profile image in the top right-hand corner and click on it. A menu will appear, and the second item down will say Your repositories. We need to click this like so:
A new page will load that shows you all of your existing repositories.
3. Locate Your Repository Settings
On this page, we need to find the repository you want to delete and click on its title.
From there, find the toolbar at the top and click the Settings tab like so:
We’re almost there.
4. Entering the Danger Zone
No, that’s not a Top Gun reference (or if it is, it’s Github’s reference, not ours!). Github actually has an area called the Danger Zone, and you have to go there to delete repositories.
Scroll down the new page until you see a section that says Danger Zone. At the bottom of the section, you’ll find a button that says Delete this repository:
We want to click this button.
5. Deleting the Repository
Warnings will appear on the screen to check that you’re sure you want to go ahead with the action:
Once you’ve read them, enter the name of your repository in the box.
Now we need to click the I understand the consequences, delete this repository button. Upon clicking this, your repository gets deleted. You’ll be taken back to GitHub’s home page, where a banner will confirm this.
Congrats, you’ve just deleted a repository in GitHub!
Common Problems When Deleting a Repository in GitHub
While deleting a repository on GitHub is usually a straightforward task, there are some common problems people face carrying it out. It’s a complex field, so issues do happen along the way, even for software developers. The good news is that there’s often a quick fix, and it can be as simple as requiring permissions.
Before we look at some of the most common problems, it’s worth noting that you can’t easily retrieve a deleted repository; all comments, packages, and admins get deleted with it, and you can’t fork a deleted repository afterward either. If all of that seems too much, and you need to reference the repository in the future, GitHub will also let you archive repositories instead of deleting them. This allows for much easier retrieval.
Let’s look at some of the most common problems users come across when deleting a repository on GitHub.
You’ve Deleted the Repository, but Only Locally
When your Git repository gets cloned using the remote hosting service (GitHub, in this case), a local copy is created on your computer. Effectively it’s an identical copy of the repository and its contents, but a local one rather than one stored in the cloud. So when you delete the repository when such a cloned copy exists, you may only have deleted the local copy.
Deleting a repository from your computer, the local copy, doesn’t remove it from the server. The server copy is the parent version, and you need to specifically delete that to fully delete the repository. Whether you’ve created a copy on purpose or by mistake, simply deleting the local variant won’t help you.
Fret not, though. Deleting the repository on the server is as simple as following our steps from earlier on—doing so removes your repository definitively. You’ll want to delete the local copy from your computer if it’s still there, too—there are cases where it remains after the process.
You Only Want To Delete the Local Repository
Flipping around the previous problem, you may actually want to delete the local repository but don’t know how to do it. Again, this is easy to do but can be confusing if you don’t understand how.
To delete a local GitHub repository, you need to enter the following into the command line:
$ rm -rf .git
That should remove the local copy from your machine. The other way to do this is to remove the directory named .git. That’s all there is to it.
On a Mac with Unix, the directory can sometimes be hidden, so you might not see it via the file browser. However, entering the following into the command line can make it show up:
rm -r .git
As we mentioned before, deleting your local copy will not affect your remote repository, so in this case, it works to your advantage.
Finally, if you want to restore your local copy, you can do so by cloning your remote repository again.
You Don’t Have Permission To Delete the Repository
Having the right permissions to accomplish tasks is a common programming problem, and it can happen when attempting to delete a repository on GitHub. You might find yourself unable to delete a repository in GitHub because the option to do so doesn’t exist. While this could be a bug, it’s more likely because you don’t have the permissions to delete the repository in the first place.
GitHub only allows members with owner privileges for an organization or admin privileges for a repository to delete an organization’s repository—you’re prevented from doing so because you’re locked out. If the setting that says Allow members to delete or transfer repositories for this organization is disabled, you can be sure that only organization owners will be able to delete any of the organization’s repositories.
If you happen to find yourself with owner privileges, then you can simply follow the steps at the start of this guide to delete the repository. However, if you don’t have access to do so, you’ll have to be granted it by the owner. An owner can customize access for each repository in your organization by assigning roles, giving people access to what they need. For example, you might want to give the ability for someone else to delete repositories on their own.
There are five different roles you can assign to someone for an organization repository. The permissions for each increase, as follows:
- Read: This level is recommended for non-coding contributors who want to view or discuss your project but nothing more.
- Triage: Triage is recommended for contributors who need to manage issues and pull requests but without the need for write access.
- Write: This is recommended for contributors who actively push to your project and need a high level of access.
- Maintain: Maintain is recommended for project managers who need to manage the repository without access to the most sensitive or destructive actions.
- Admin: The final level is only recommended for people who need full access to the project, including sensitive and destructive actions like managing security or deleting a repository—it shouldn’t be given out lightly because weeks or months of work can be lost in a few clicks.
It’s worth mentioning that if your organization uses GitHub Enterprise Cloud, then you can create custom repository roles that fall somewhere in-between the five roles above. Owners can choose the base permissions that apply to all members of an organization when accessing any of the repositories. The ability to limit access to certain settings is possible, and other actions across the organization can be tweaked as required.
Organization owners will have admin-level access to every repository by default, so there’s no need to do anything else if that’s you—you’re free to delete them as you need. Keep in mind that when someone adds what’s known as a deploy key to a repository, any user who has the private key can read or write to the repository.
You Can’t Delete the Repository Even As the Owner
There have been cases of users logging into GitHub to delete a repository—those with admin-level privileges—and being unable to do so. This scenario is particularly frustrating if they are the owner of the repository itself, and yet it can still happen.
Typically, when users go to Settings to delete the repository, they find the tab doesn’t show or that it’s blanked out. They may have even tried to push to the repository and found themselves looking at a 403 error. While this isn’t as common as some of the problems you might encounter, it’s nevertheless the last thing you want. So, what can you do about it?
The first thing to try is to clear your cache and cookies, as this can sometimes interfere with the loading of web pages. A cookie leaves tiny bits of information when you’ve left a site, so it might be affecting your ability to delete the repository. The cache is really about making your loading times faster, but it doesn’t hurt to try and clear this anyway, as it can still inhibit what you’re able to do. Most web browsers allow you to clear your cache and cookies in less than a minute.
The other thing it could be is as simple as in-progress updates on the GitHub website. Come back after a little while and see if you’re receiving the same message. Sometimes patience is all it takes, and it fixes itself.
If you’ve done both of those and are still having no luck, it may be a problem with your specific GitHub account. Unfortunately, this can sometimes occur inexplicably, and the best bet is to contact the GitHub support team. You can find a contact form here, and you can also reach them via email or live chat if needed. Don’t forget to ask the vast GitHub community for support either; the community has solved many a seemingly impossible problem before.
You’ve Deleted a Repository and Now Can’t Restore It
You might have changed your mind and now realize archiving your repository was a better option, but the problem is, you’re finding it difficult to restore. Deleting a repository has some finality to it, so you need to think carefully before taking action. That said, it is possible to restore your repository, and there are a few reasons why you might be finding it difficult to do.
The first thing to note is that a deleted repository can be restored within 90 days of its deletion, unless the repository was part of a fork network that’s not currently empty. A fork network contains the parent repository and other forks. If your repository was part of a fork network, you can’t restore it unless every other repository in the network gets deleted.
If you need to restore a repository that was part of a fork network and one which isn’t currently empty, you’ll need to contact the GitHub team and go from there. Keep in mind that it can also take up to an hour for a repository to be available for restoration after being deleted. If it’s been a few hours and you still can’t restore it, either contact the team or ask the community for help.
While restoring a repository is achievable, you won’t get back your release attachments or the team permissions from before. Restored issues are also not labeled, so it can create extra work if you’re not careful. It’s best to take some time before rushing in and deleting a repository altogether—for some, of course, it will still make sense to do so; just be aware of the changes it makes afterward.