GitHub delete repository the RIGHT way [Step-by-Step]

Brief workflow steps to delete Github repository

Deleting the Github repository is simple.

You can delete the directory containing the repo

Advertisement
rm -rf <root directory>

or

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.

  1. Access the main page of the target repo.
  2. Click Settings on the navigation menu
  3. Scroll down until you see Danger Zone
  4. Click on Delete this repository
  5. 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.

Advertisement

I am creating a repo called github_delete_repo on Github.

GitHub delete repository the RIGHT way [Step-by-Step]

Copy the repo URL.

GitHub delete repository the RIGHT way [Step-by-Step]

Clone it on the command line.

GitHub delete repository the RIGHT way [Step-by-Step]

and cd into it.

cd github_delete_repo

Let us build the repo locally before seeing examples of the Github delete repository.

We currently have one commit history and a README.md file.

git log --oneline

ls

GitHub delete repository the RIGHT way [Step-by-Step]

Let us create more files.

touch file1.py file2.js

Stage the files

Advertisement
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 *

Commit them.

git commit -m "add html file"

Let us check the commit history.

git log --oneline

We have three commits in the history.

GitHub delete repository the RIGHT way [Step-by-Step]

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:

ls -a

or align the files and directories vertically by adding the -l flag.

ls -la

GitHub delete repository the RIGHT way [Step-by-Step]

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

  1. bare

The --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 <project.git> folder.

 

  1. template

The --template flag is crucial when creating a reference directory. Like the unflagged repo, the --template flag:

git init --template=<template_directory>

creates a repo with a .git subdirectory, enabling you to copy files.

 

  1. separate

Instantiating a repo with the --separate flag:

git init --separate-git-dir <target directory>

creates a text file with the path to the target directory.

 

  1. quiet

The --quiet flag allows you to only interact with the most critical messages, errors, and errors. You can either use

git init --quiet

or

git init -q

to instantiate a quiet repo.

 

  1. shared

With the --shared flag

git --shared[=<permissions>]

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 .git sub-directory.

Let us get out of the cloned Github repo.

cd ..

and create another repo

mkdir local_repo
cd local_repo

then initialize it

git init

Listing all files

ls -la

shows we have a .git sub-directory.

GitHub delete repository the RIGHT way [Step-by-Step]

Let us return to the root directory

cd ..

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 .git sub-directory.

cd github_delete_repo

Check repo presence:

ls -la

then run the following command to Github delete repository locally.

rm -rf .git

where 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.

github delete repo on command line

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.

GitHub delete repository the RIGHT way [Step-by-Step]

You get to the Sign in page, permitting you to view all your repos.GitHub delete repository the RIGHT way [Step-by-Step]

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:

GitHub delete repository the RIGHT way [Step-by-Step]

 

Step-3. Click Settings on the navigation menu

Click the highlighted Settings tab, as shown here.GitHub delete repository the RIGHT way [Step-by-Step]

 

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.

GitHub delete repository the RIGHT way [Step-by-Step]

 

Step-5. Click on Delete this repository

GitHub delete repository the RIGHT way [Step-by-Step]

 

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 delete repository the RIGHT way [Step-by-Step]

Github redirects us to the main page with a success message, Your repository "Stevealila/github_delete_repo" was successfully deleted.

 

Conclusion

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.

 

Didn't find what you were looking for? Perform a quick search across GoLinuxCloud

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can either use the comments section or contact me form.

Thank You for your support!!

Leave a Comment