How to Delete a Git Repository
Last Updated :
31 Jan, 2024
GAs developers and software teams are collaborating on projects, the usability of version control systems like Git to track changes and manage codebases has increased a lot. Using Git, developers can create and maintain repositories, that store the complete history and versions of projects. However, there are situations when deleting a git repository become necessary.
In this article, we will learn the steps to delete both local and Git repositories. We will ensure that the project is completely removed from the local system's environment. Also, we will explain the process of deleting a remote repository hosted on platforms like GitHub, GitLab.
Method-1: Deleting the Repository from the Command line
When a user clones a Git repository from Github using the command git clone <url>, they get a copy of the remote repo on their local computer so that they can work on it on their current working directory where the repo got cloned without directly making changes on the remote repository.
If you want to delete a local Github Repository that was cloned from to local computer without touching or making any changes to the Remote GitHub repository then follow the commands below:
Step 1: Go into your project file
The deletion of the '.git' file, will delete the .git file that contains a log of the commit history, its information, and also the remote repository address from the working directory. We can think of this deletion as when we do git init to initialize the current working directory as a Git directory, with the above command we are just reverting it back to not being a Git directory.Â
And what about the files and folders in the present working directory?
This has to be deleted using the following set of commands.
cd <project_name>
rm -rf <repository_folder>.gitÂ

What are rm and rf commands?
- In Linux, the user can delete/remove directories using rmdir or rm, in the above case we have made use of rm which is used to remove non-empty directories, unlike rmdir which is used to remove empty directories.
- This command is used to remove non-empty directories and all the files in the directory without being prompted if a directory or a file in the current working directory is write-protected (this case is very common when working on a forked repository from GitHub) and the user is prompted to provide Y (for yes) to confirm the deletion of the write-protected file. Now using -rf with rm is effective as it can skip part of the user being prompted every time.
Step 2: Verifying Git Repository is Deleted
To verify whether the targeted repository is deleted or not, check its status using the below command in the current directory and if the error is showing after running of command it means, we have successfully deleted a Git Repository.
git status
Step 3(Optional): ( if you want to initialize the working directory to another GitHub Repository See Additional steps below):-
Go to the directory where the project is present (Note: Don't go inside the project file).
rm -rf <folder_name>

Additional Steps:
Suppose you want to initialize (git init) a new GitHub repository, and then add it to a new remote repository and then start adding and committing to the files being added from the current working directory.
- Make sure that the current working directory is the directory that needs to be pushed to the open-source platform (GitHub).
- git init
- git remote add origin https://github.com/user/repo.git
- git push -u origin master
Method-2: Deleting the Repository from GitHub Website
Step 1: Navigate to your project
https://github.com/your-github-username/Project-Name

Step 2: Go to the settings option on the top right corner like the image above, and navigate down to the danger zoneÂ

Step 3: Go and click on the delete this repository button and after which you will be prompted to make sure you are deleting and all these actions will permanently affect the repository, in the box type your-username/project-name (replace it with yours).Â
You may also be prompted to type in the GitHub password.

Following these steps will make sure you have completely deleted the repository from the local PC as well as the GitHub site.
Deleting the File from GitHub Website
Here we are going to delete a particular file from our GitHub using Github. This feature can be useful when we have by, mistake added a few files in our project but we no longer need that.
Step 1: Navigate to your project
https://github.com/your-github-username/Project-Name
Step 2: Browse to the file in your repository that you want to delete.
At the top of the file, click on the Delete Icon.

Step 3: At the bottom of the page, type a short, meaningful commit message that describes the change you made to the file

Then it will show an alert like this that the File was successfully deleted.

Conclusion
There may be several reasons to delete a Git Repository, whether your work is completed in a particular project or you want to create space in your computer by deleting files. And, deleting a git repository is very simple as well. You just need to manually delete the files in a project till all the files will be deleted. But git repositories have a hidden folder named .git and you have to delete that also to fully delete a git repository. Whether you want to delete a git repository locally or want to delete a git repository on GitHub, both methods are very simple and explained in the article above.
Similar Reads
How to Delete a File From a Git Repository?
Managing files within a Git repository often involves adding new files, modifying existing ones, and sometimes, deleting files that are no longer needed. Deleting a file from a Git repository is a simple process, but it's essential to follow the correct steps to ensure that the repository remains co
3 min read
How to Git Clone a Local Repository?
Git is a powerful version control system widely used for tracking changes in source code during software development. One of the fundamental operations in Git is cloning a repository, which involves making a copy of an existing repository. While most tutorials cover cloning a remote repository, you
3 min read
How to Fork a GitHub Repository?
GitHub is a great application that helps you manage your Git repositories. Forking a GitHub repository is a common practice that allows you to create your own copy of a repository hosted on GitHub. In this article, we will learn more about Git-Fork and its uses. Table of Content What is GitHub Repos
3 min read
How to Git Clone a Remote Repository?
Git is a powerful version control system that allows developers to track changes, collaborate on code, and manage projects efficiently. One of the fundamental operations in Git is cloning a remote repository. This article will guide you through the process of cloning a remote Git repository. Prerequ
3 min read
How To Clone a Repository From Gitlab?
Cloning a repository in Git involves creating a local copy of a project from a remote server. This allows you to work on the project on your local machine and later push your changes back to the remote repository. GitLab, one of the popular platforms for hosting Git repositories, provides a straight
3 min read
How to Delete a Remote Tag in Git?
Git tags are important for marking specific points in your repository's history, often used for releases. However, there may come a time when you need to delete a remote tag. Hereâs a simple guide to help you understand how to do this. Table of Content What is a Git Tag?Why Delete a Remote Tag?Steps
2 min read
How To Delete Remote Branch in Git?
Git is an important tool in the process of application development and is used widely in the software industry by developers to maintain the codebase. Using this developers are able to organize their codebase and manage the version history of their project. Now, as a developer, you need to know how
1 min read
How to Remove Directory From a Git Repository?
Managing files and directories within a Git repository is a common task, especially when you need to clean up or reorganize your project's structure. Removing a directory from a Git repository involves several steps to ensure that the change is tracked and applied correctly. In this article, we will
2 min read
How to Fully Delete a Git Repository Created With Init?
Creating a Git repository with git init is a great way to start managing your project with version control. Git helps developers keep track of changes in their code, collaborate with others, and maintain different versions of their projects. However, there are situations where you might want to comp
3 min read
How to Delete a Branch in Git?
When working with Git, itâs common to create branches to isolate changes and work on new features or fixes. However, once a branch has served its purpose, itâs often necessary to delete it to keep your repository clean and organized. In this article, weâll see the process of deleting a Git branch us
3 min read