The best answers to the question “How to fully delete a git repository created with init?” in the category Dev.
I created a git repository with
git init. I’d like to delete it entirely and init a new one.
If you really want to remove all of the repository, leaving only the working directory then it should be as simple as this.
rm -rf .git
The usual provisos about
rm -rf apply. Make sure you have an up to date backup and are absolutely sure that you’re in the right place before running the command. etc., etc.
Git keeps all of its files in the
.git directory. Just remove that one and init again.
If you can’t find it, it’s because it is hidden.
In Windows 7, you need to go to your folder, click on Organize on the top left, then click on Folder and search options, then click on the View tab and click on the Show hidden files, folders and drives radio button.
On a Mac OS:
Open a Terminal (via Spotlight: press CMD + SPACE, type
terminaland press Enter) and run:
defaults write com.apple.finder AppleShowAllFiles 1 && killall Finder
Note: The keyboard shortcut to show hidden files in Finder is
CMD + SHIFT + . so it is no longer necessary to modify the
finder config this way
You could also type
cd(the space is important), drag and drop your git repo folder from Finder to the terminal window, press return, then type
rm -fr .git, then return again.
On Ubuntu, use shortcut Ctrl + H.
Alternative to killing TortoiseGit:
- Open the TortoiseGit-Settings (right click to any folder, TortoiseGit → Settings)
- Go to the Icon Overlays option.
- Change the Status Cache from Default to None
- Now you can delete the directory (either with Windows Explorer or
rmdir /S /Q)
- Set back the Status Cache from None to Default and you should be fine again…
If you want to delete all .git folders in a project use the following command:
find . -type f | grep -i "\.git" | xargs rm
This will also delete all the .git folders and .gitignore files from all subfolders