You can delete a Git repository by removing its folder, but the method depends on whether you want to keep the code elsewhere
A Git repository is just a folder on your computer with a hidden .git directory inside it. Deleting the repository means deleting that entire folder. If you have pushed your code to GitHub, GitLab, or another remote service, the code stays there — deleting your local folder does not erase the remote copy. If you have not pushed anywhere, deleting the folder erases your local history.
Before you delete, decide: do you want to keep a copy of the code somewhere else? If yes, push to a remote first or copy the folder to a backup location. If you are certain you do not need the code, you can delete the folder directly from your file manager or from the command line.
Key Takeaways
- Deleting a Git repository folder does not affect code you have already pushed to GitHub or another remote service.
- If you have not pushed your code anywhere, deleting the folder erases your entire local history and all branches.
- You can delete a repository using your file manager (Finder, File Explorer, Nautilus) or the command line with rm -rf.
- Before deleting, run git remote -v to confirm whether you have a remote backup, and run git log --oneline to see what you are about to lose.
Check what you have before you delete
Open a terminal or command prompt, navigate into the repository folder, and run two commands to see what you are about to lose.
First, check whether you have a remote backup by running git remote -v. If you see output like origin https://github.com/yourname/repo.git (fetch), your code is backed up on that remote service. If you see nothing, you have no remote backup — the code exists only on your computer.
Second, see what commits you have by running git log --oneline. This shows you every commit in your current branch. If the list is long and you are not sure whether you want to lose it, copy and paste the output into a text file as a record before you delete.
Delete the repository using your file manager
The simplest method is to use the file manager you already use every day. Open Finder (Mac), File Explorer (Windows), or Nautilus (Linux), navigate to the folder that contains your repository, right-click the repository folder, and select Delete or Move to Trash.
On Mac, the folder moves to Trash and stays there until you empty the Trash. On Windows, it moves to the Recycle Bin. On Linux, it moves to Trash depending on your desktop environment. You can recover the folder from Trash or Recycle Bin if you change your mind within a few days, but once you empty the trash permanently, recovery becomes much harder.
Delete the repository from the command line
If you prefer the terminal, navigate to the parent directory (the folder that contains your repository) and run rm -rf repository-name, replacing repository-name with the actual folder name. The -rf flags mean "recursive" and "force" — the command deletes the folder and everything inside it without asking for confirmation.
This method is faster than using the file manager, but it does not move the folder to Trash first. The deletion is when ready. If you are not certain, use the file manager method instead so you can recover from Trash if you change your mind.
On Windows, if you are using PowerShell or Command Prompt, you can also use rmdir /s /q repository-name to delete the folder and all its contents without confirmation.
What happens to your code after deletion
If you pushed your code to GitHub, GitLab, Bitbucket, or another remote service before deleting, your code is still there. You can clone the repository again to your computer at any time by running git clone https://github.com/yourname/repo.git (using your actual remote URL). Your commit history, branches, and all your work remain on the remote service.
If you did not push anywhere, deleting the folder erases everything — all commits, all branches, all history. The only way to recover it is if you have a backup of the folder itself, or if you use file recovery software on your computer (which may or may not work depending on how your operating system handles deleted files).
Reasons to delete a repository
You might delete a repository because the project is finished and you do not need the code anymore. You might delete it because you moved the code to a different location or a different computer. You might delete it because you want to start fresh with a clean clone from the remote.
If you want to start fresh but keep your history, do not delete. Instead, run git fetch origin to update your local copy with the latest remote changes, or run git reset --hard origin/main to reset your current branch to match the remote (replacing main with your actual branch name).
Frequently Asked Questions
Does deleting the folder delete my code from GitHub?
No. Deleting your local folder does not touch GitHub or any other remote service. Your code stays on GitHub until you delete the repository there. To delete a GitHub repository, log in to GitHub, go to the repository settings, scroll to the danger zone, and click Delete This Repository.
Can I recover a deleted repository?
If you deleted the folder using your file manager, it is in Trash or Recycle Bin and you can restore it. If you used rm -rf, recovery is harder but possible with file recovery software. If you pushed to GitHub first, you can clone it again anytime. If you did not push anywhere and permanently deleted the folder, recovery is unlikely.
What if I deleted the repository by accident?
Check your Trash or Recycle Bin first — if it is there, restore it. If you used the command line and it is gone from Trash, try file recovery software. If you had pushed to GitHub, clone the repository again. If none of those work, the code is lost.
Do I need to do anything in Git before I delete the folder?
No. Git does not prevent you from deleting the folder. Just make sure you have pushed to a remote first if you want to keep the code. Running git remote -v before you delete confirms whether you have a backup.