How to delete a Git repository
Delete Git repo locally
There’s not trick in terms of how to delete a Git repo locally from your computer. You just need to delete all of the content from the folder in which the Git repo was either cloned or initialized. That’s it.
Okay, maybe there is a bit of a trick. Every Git repo has a hidden folder named .git in which the DVCS tool stores all of its configuration data. If your computer hasn’t been configured to show hidden files and folders, attempts to locally delete a Git repo will fail, because the hidden .git folder will remain. Configure your computer to show local folders, delete the .git folder using your operating system’s File Explorer, the the local Git repository is removed.
Steps to delete a local Git repo
To delete a Git repository locally, follow these steps:
- Open the the local Git repo’s root folder
- Delete all of the files and folder in the Git repo’s root folder
- Delete the hidden .git folder with File Explorer or through the command line
- Run a git status command. A fatal: not a git repository error verifies that the Git repo is deleted
Command line Git repository delete
If you’re familiar with the terminal window or the DOS prompt, you can easily perform a command line Git repository delete. Just run the rm command with the -f and -r switch to recursively remove the .git folder and all of the files and folders it contains.
This Git repo remove command also allows you to delete the Git repo while allowing all of the other files and folder to remain untouched.
[email protected] /c/remove/repository (main-branch) $ rm -fr .git
Verify Git repo is removed
If you use the Git BASH terminal window to remove the Git repository, you will notice the name of the current Git branch is no longer listed once the Git removal command is issued.
[email protected] /c/remove/repository $ git status fatal: not a git repository (or any of the parent directories): .git
Furthermore, any git commands you issue will return with a fatal: not a git repository error. While errors aren’t typically the way we seek confirmation in the software development work, in this case, seeing this fatal error is proof that the local Git repository delete operation ran successfully.