Delete a Git Repository

Whether you're tidying up old projects, or need to address a mistake, it's essential to know how to properly delete both local and remote Git repositories repositories.

You probably either want to:

Deleting a Local Repository

If you simply wish to delete a Git repository from your local machine, you're essentially looking to delete the .git folder present in your repository.

On Windows:

Using the Command Prompt or PowerShell:

rmdir .git

If you have .gitignore and .gitmodules files you want to get rid of too:

del .git*

Of course you can also use Explorer to delete the .git folder.

To view hidden files and folders in Windows:

  1. Open File Explorer from the taskbar.
  2. Select View > Show > Hidden items.

On Linux and Mac OSX:

Using the Terminal:

rm -rf .git

To delete .gitignore and .gitmodules as well:

rm -rf .git*

Mac OS X Hidden Files:

To view hidden folders in Finder (Mac OS X), execute these commands in your terminal window:

defaults write com.apple.finder AppleShowAllFiles TRUE
killall Finder

Delete a Git repository using VS Code

If you're using Visual Studio Code, simply navigate to the repository's location and delete the .git folder to remove the Git repository.

Deleting a Remote Repository

Deleting a GitHub repository:

  1. Navigate to the main page of the repository on GitHub.
  2. Under your repository name, click Settings. If you cannot see the "Settings" tab, select the dropdown menu, then click Settings.
  3. Scroll down to the "Danger Zone" section, and click Delete this repository.
  4. Read the warnings carefully.
  5. To verify you're deleting the correct repository, in the text box, type the name of the repository you wish to delete.
  6. Click I understand the consequences, delete this repository.

Warnings for GitHub:

  • Deleting a public repository will not delete any forks of the repository.
  • Deleting a private repository will delete all forks of the repository.
  • Some deleted repositories can be restored within 90 days of deletion.

Deleting a GitLab repository:

(Note: The exact steps can vary depending on GitLab's version and customizations.)

  1. Navigate to the main page of the repository on GitLab.com.
  2. Go to Settings > General.
  3. Scroll to the "Advanced" section and then choose Remove project.
  4. Follow the prompts to confirm the deletion.

Deleting a Gitea repository:

  1. Go to Settings of the repository.
  2. Navigate to the Dangerous Zone.
  3. Click Delete this repository.

Conclusion

It's crucial to approach the process of deleting repositories with caution. Always make sure to backup any essential data or code before deletion. Remember, while some platforms offer a grace period for restoring deleted repositories, not all actions are reversible.

Hosted Gitea is a fully managed Gitea hosting service. If you're looking for a private alternative to GitHub or Gitlab check out our service.

Get your Gitea server