Deleting a GitHub Repository: A Simple Guide for Beginners

So you‘ve created a repository on GitHub but now want to remove it? Not a problem! Deleting unwanted repositories is a common task for developers. In this beginner-friendly guide, I‘ll walk you through the main ways to easily delete a GitHub repository.

Why Would You Want to Delete a GitHub Repo?

First, what exactly is a GitHub repository? A repository (or repo for short) is essentially a central file storage location used to organize a single project. It contains all of your project‘s files and revision history.

There are a few common reasons you may want to delete a GitHub repo:

  • You no longer need the project: Perhaps you created a simple test repository when learning GitHub. Now that you‘re done experimenting, you can delete unneeded practice repos.

  • The repo contains sensitive data: Uh oh, you accidentally included some API keys or other private info in a public repository! Deleting it ASAP is the best move.

  • You created a duplicate repo: With a misplaced click or GitHub glitch, duplicate repos can mysteriously appear. Time for some cleanup!

What Happens When a GitHub Repository Is Deleted?

Before we dive into the how-to, let‘s briefly go over what happens when you delete a GitHub repo:

  • All files and commit history are destroyed: So be absolutely sure you have backups if needed!

  • Issues and pull requests associated with the repo are also deleted: Any open issues or pull requests will be gone.

  • Forked repositories remain unaffected: If others have forked your repo, their forked copies persist after you delete the original.

  • You can restore deleted public repos within 90 days: Like files on your computer, deleted GitHub repos aren‘t immediately wiped from existence. But don‘t wait too long!

Now that you know the basics, let‘s explore the main ways to delete a GitHub repository.

Method #1: Delete a GitHub Repository from the GitHub Website

The easiest way to remove a repository is directly through the GitHub website:

Step 1: Navigate to Your GitHub Profile

Log into your GitHub account and click on your profile icon in the top right corner:

GitHub Profile Dropdown

Step 2: Access Your Repository List

Select "Your repositories" to view all of your existing repos:

GitHub Your Repositories

You can also access repository settings from within an individual repo page.

Step 3: Choose the Repository You Want to Delete

Browse or search to locate the specific repository you want to delete.

Step 4: Access the Repo Settings

Below the repository name, click the "Settings" tab to access details:

GitHub Repo Settings Button

Step 5: Scroll to the Danger Zone

Near the bottom is the ominously named "Danger Zone" section. This is where repository deletion happens!

GitHub Danger Zone

Step 6: Click "Delete This Repository"

Press the large red button to kick off the deletion process.

Step 7: Verify Repository Deletion

Double and triple check you have the correct repo! Type in the full repository name and click the newly enabled "I understand…" button:

GitHub Verify Delete

After a quick refresh, your disappeared repository will be gone for good (or at least 90 days until final deletion).

And that‘s all there is to it! The main steps are accessing the settings, finding the Danger Zone, and verifying the name.

Now let‘s look at deleting through an alternative method – the GitHub CLI.

Method #2: Deleting a GitHub Repository via the GitHub CLI

The GitHub CLI (Command Line Interface) allows you to manage GitHub repositories and other elements directly from the command line or terminal.

To delete repos using the CLI, you‘ll need to first install and set up the GitHub CLI tool. Don‘t worry, I‘ll cover how it works below!

Step 1: Install GitHub CLI

Installation processes vary based on operating system. Follow the official installation guide for your system.

On Ubuntu Linux, installing is as simple as:

sudo apt install gh

Or with Homebrew on MacOS:

brew install gh 

Step 2: Authenticate GitHub CLI

After installation, you‘ll need to verify GitHub CLI can access your account using either the browser-based OAuth flow or a personal access token.

Example initializing interactive OAuth verification:

gh auth login

Step 3: Delete the Repository

With GitHub CLI ready, deleting a repository takes just one command in the terminal.

Use the gh repo delete command followed by the repository name:

gh repo delete my-old-repository

You may be prompted to enter the full repository name again to confirm deletion.

And just like that, your repository will be scheduled for removal!

The GitHub CLI provides a streamlined way to manage repositories without leaving the command line.

What Are Some Alternatives to Deleting Repositories?

Deleting isn‘t your only option for removing a repository from public view or limiting access. Here are a few alternatives you can consider first:

Make the Repository Private

Rather than fully deleting, you can simply make your public repository private. Just like human friendships, your repo can go from public to private but not vice versa.

Follow these steps to quickly convert your repo from public to private.

Making private restricts access to only people you explicitly share with rather than the whole world.

Delete Specific Branches

If you use Git branching, deleting old branches you no longer need cleans things up.

View all branches by selecting the "X branches" link:

View GitHub Branches

On the branches page, press the trash can icon to delete each unneeded branch:

Delete GitHub Branch

Removing stale branches makes ongoing development easier to navigate.

Delete Individual Files

Rather than removing everything, deleting specific files containing sensitive keys or credentials is an option.

Navigate into the file you want to remove, click the trash can icon on the upper right, and commit the change.

This surgical approach preserves your repository while excising problematic pieces.

FAQs and Additional Info

What‘s the Difference Between GitHub and Git?

This is a common confusion! Git is an underlying version control system that tracks changes to your code and facilitates branching and merging. It enables developers to collaborate on the same codebase.

GitHub is a host or front-end interface built on top of Git. GitHub provides cloud storage and additional tools to manage repositories online.

You use Git commands locally and GitHub for remote synchronization and hosting.

Is GitHub Free?

GitHub actually has both free and paid tiers available. Free GitHub accounts allow unlimited public repositories and collaborators. Paid plans add features like unlimited private repositories, Gists, teams, and advanced analytics.

So GitHub has a generous free offering, but enterprise teams may benefit from upgraded paid plans.

Are There GitHub Alternatives?

Yes, GitHub is not your only option! Popular alternatives for remote Git repository hosting include:

  • GitLab: Web-based Git repo manager with unlimited private/public repositories under their free tier.
  • Bitbucket: Offers unlimited private repositories with smaller teams for free.
  • SourceForge: One of the first and largest repo hosts, focused on open source projects.

Each has pros and cons to weigh based on your needs.

Can You Use Third-Party Apps to Delete GitHub Repositories?

Indeed you can utilize external applications to manage your GitHub repositories:

  • GitHub Desktop: This official electron app from GitHub allows you to visually interact with your GitHub repos locally or remotely.
  • GitKraken: A cross-platform Git GUI client with intuitive visual representation of repositories. Offers a premium "pro" version alongside free access with some limitations.

I‘d advise checking any third-party apps are from a reputable provider before granting access to your GitHub account. Verify what permissions and data the app can access to ensure your account security isn‘t compromised.

Let‘s Recap – How Do I Delete a GitHub Repository?

Few key takeaways for easily removing a GitHub repository:

  • Delete directly from the GitHub web interface by going to settings and finding the "Delete This Repository" button
  • Use the GitHub CLI program after installation to delete from your terminal with the gh repo delete command
  • Adjust visibility or delete branches/files rather than removing everything
  • You can restore accidentally deleted public repositories within 90 days through site-wide search

And that’s a wrap! I hope this step-by-step guide gave you a detailed overview of the options for easily deleting GitHub repositories as a beginner. Let me know if you have any other questions!