Table of Contents
Brief workflow steps to delete Github repository
Deleting the Github repository is simple.
You can delete the directory containing the repo
rm -rf <root directory>
navigate to the directory hosting the repo and run this command to Github delete repository on your command line.
rm -rf .git
The last step is to head over to the Github website and follow these to delete the target repository.
- Access the main page of the target repo.
- Click Settings on the navigation menu
- Scroll down until you see Danger Zone
- Click on Delete this repository
- Type the repo name and accept the warnings
The above are typical routes to Github delete repository. What if you want to explore the nitty-gritty of deleting the Github repository?
That is why it would help to find practical ways to Github delete repository by following this tutorial to the end. Let us get started.
Lab setup to practice Github delete repository
We will imitate a typical development environment where you create a repo, clone it, make commits and push the changes to Github. We will then assume we no longer need the repo and delete it on the command line and Github.com.
I am creating a repo called
github_delete_repo on Github.
Copy the repo URL.
Clone it on the command line.
cd into it.
Let us build the repo locally before seeing examples of the Github delete repository.
We currently have one commit history and a
git log --oneline ls
Let us create more files.
touch file1.py file2.js
Stage the files
git add .
and commit them.
git commit -m "track Python and Js"
Repeat the process to create the third commit history.
Create two more files
touch deleted.txt index.html
And stage them.
git add *
git commit -m "add html file"
Let us check the commit history.
git log --oneline
We have three commits in the history.
Now that we have an active repo with some commits to practice the Github delete repository, let us apply the setup to the command line before remote repo deletion.
Github delete repository using the command line
Github delete repository on the command line starts by identifying the location of the target repo. For that reason, it would help to understand how a repository exists on your computer before deleting it.
How Github repository resides on your computer
Initializing a repository on any directory creates a
.git sub-directory on your computer.
.git sub-directory has all the information about the tracked project, such as commits, commit objects and commit history.
The sub-directory is hidden on both command line or GUI by default. To see the folder on the command line or terminal, run the
ls command with the
-a flag, as follows:
or align the files and directories vertically by adding the
The limit of interacting with instantiated repo depends on the git init flag used. For instance, instantiating an empty repo without a flag allows you to create a file, stage, and commit changes to the repo.
On the other hand, most flags like
--bare only allow you to do push or pull requests to the repo. This is because you lack a working directory to add changes or do commits. Here is brief information about standard git init flags:
Common flags determining interaction with the local git repository
--bare flag enables you to handle push and pull requests only. You can neither add nor commit to the repo.
Running the command
git init --bare
makes git to ignore on the working directory when initializing the repo. The tracked files reside in the
--template flag is crucial when creating a reference directory. Like the unflagged repo, the
git init --template=<template_directory>
creates a repo with a
.git subdirectory, enabling you to copy files.
Instantiating a repo with the
git init --separate-git-dir <target directory>
creates a text file with the path to the target directory.
--quiet flag allows you to only interact with the most critical messages, errors, and errors. You can either use
git init --quiet
git init -q
to instantiate a quiet repo.
you can specify user permissions for pushing or pulling changes to the repo. Examples of permissions to configure are TRUE, FALSE, GROUP, ALL, or EVERYBODY.
Now that you know how the repo resides on your computer, let us see two typical ways to delete it on the command line.
Delete the root directory
This is a dangerous route to take when doing Github delete repository on the command line because you cannot recover any files after the action.
Think of the
.git sub-directory as a room within a house. One way to destroy the room is to damage the entire house. In our case, we can create and delete a repository by removing the directory containing the
Let us get out of the cloned Github repo.
and create another repo
then initialize it
Listing all files
shows we have a
Let us return to the root directory
before deleting the target folder using the
-rf flag, as follows:
rm -rf local_repo
Both repo and directory are gone!
Delete only the git sub-directory
Sometimes you need to delete a Github repo on the terminal or command line without clearing the files. Let us follow these steps to achieve that.
Navigate to the directory containing the
Check repo presence:
then run the following command to Github delete repository locally.
rm -rf .git
rm stands for remove,
-r means recursively removing the target files whose directory we have specified, whereas the
-f flag means overriding every change till the up-to-date check.
Recheck the repository.
The local version of the Github repository got deleted.
Method-2: Github delete repository from the website
Deleting a repo on the Github website is pretty straightforward. Follow these steps to achieve that.
Step-1. Move to github.com
Click the Sign in tab to access to your Github account.
You get to the Sign in page, permitting you to view all your repos.
Let us find the
github_delete_repo repo we created earlier among the list of repos.
Step-2. Access the main page of the target repo
Click on the target repo. We land on a repo's page appearing, as follows:
Step-3. Click Settings on the navigation menu
Click the highlighted Settings tab, as shown here.
Step-4. Scroll down until you see Danger Zone
You should the Change repository visibility, Transfer ownership, Archive this repository, and Delete this repository buttons.
Step-5. Click on Delete this repository
Step-6. Type the repo name and accept the warnings
Let us copy and paste the repo name,
Stevealila/github_delete_repo, above the input box or type each letter until the box named I understand the consequences, delete this repository becomes active.
Github redirects us to the main page with a success message, Your repository "Stevealila/github_delete_repo" was successfully deleted.
You can Github delete repository by discarding a directory containing the repo, removing the
.git sub-directory on the command line, or following the steps outlined in this tutorial to delete the repo on the Github website.