How to fully delete a git repository created with init?

Peiniau Source

I created a git repository with git init. I'd like to delete it entirely and init a new one.

gitgit-init

Answers

answered 9 years ago Kristof Provost #1

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 terminal and press Enter) and do this command: defaults write com.apple.finder AppleShowAllFiles 1 && killall Finder.

    • Or 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.

answered 9 years ago Charles Bailey #2

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.

answered 7 years ago eckes #3

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...

answered 6 years ago ejazz #4

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

answered 6 years ago Scorpius #5

Where $GIT_DIR is the path to the folder to be searched (the git repo path), execute the following in terminal.

find $GIT_DIR -name *.git* -ok rm -Rf {} \;

This will recursively search for any directories or files containing ".git" in the file/directory name within the specified Git directory. This will include .git/ and .gitignore files and any other .git-like assets. The command is interactive and will ask before removing. To proceed with the deletion, simply enter y, then Enter.

answered 5 years ago Tolga Yılmaz #6

  • Remove /var/www/gitorious (or where you installed it in)
  • Remove services in /etc/monitd
  • Remove git user
  • Remove /usr/local/activemq and init script for it in /etc/init.d/act

answered 3 years ago P.Brian.Mackey #7

I tried:

rm -rf .git and also

Git keeps all of its files in the .git directory. Just remove that one and init again.

Neither worked for me. Here's what did:

  • Delete all files except for .git
  • git add . -A
  • git commit -m "deleted entire project"
  • git push

Then create / restore the project from backup:

  • Create new project files (or copy paste a backup)
  • git add . -A
  • git commit -m "recreated project"
  • git push

answered 2 years ago Ahmad Awais #8

You can create an alias for it. I am using ZSH shell with Oh-my-Zsh and here is an handy alias:

# delete and re-init git
# usage: just type 'gdelinit' in a local repository
alias gdelinit="trash .git && git init"

I am using Trash to trash the .git folder since using rm is really dangerous:

trash .git

Then I am re-initializing the git repo:

git init

answered 2 years ago kamal #9

cd to the directory from which git need to be deleted and run command

Mac OS or any Linux distro

rm -rf .git

answered 2 years ago user2340356 #10

u can also deleted these folders and files where u have a git repository

http://storage9.static.itmages.com/i/16/0410/h_1460324963_2968655_d38544bf73.png

answered 2 years ago hyip #11

I just collect the ones which work best for me:

cd <repository-name>
find . -type f | grep -i "\.git" | xargs rm
cd ..
rm -rf <repository-name>
mkdir <repository-name>
cd <repository-name>
git init

answered 1 year ago Urvashi Gupta #12

You can use the following command from the command line-

rm -rf .git

Here rm means remove, -rf means recursive force and .git is the repo/file you want to remove. Please be careful when using this command. If you tried to rm -rf any other files or folder, they may be permanently deleted. Never ever run this on your Desktop. You can wipe off all your work. Be careful when using this command.

answered 10 months ago A. Pandey #13

I did this, and it worked just fine.
1. Remove the .git file from the repo by rm -fr .git
2. Remove the repo folder by rm -R path\your_repo_name

answered 6 months ago squal #14

To fully delete the .git repository in your computer (in Windows 8 and above):

  1. The .git repository is normally hidden in windows
  2. So you need to mark the "hidden items" to show the hidden folders
  3. At the top site of you directory you find "view" option
  4. Inside "view" option you find "hidden items" and mark it
  5. Then you see the .git repository then you can delete it

answered 3 months ago sahil khurana #15

In windows:

  1. Press Start Button
  2. Search Resource Monitor
  3. Under CPU Tab -> type .git -> right click rundll32 and end process

Now you can delete .git folder

answered 3 weeks ago SridharKritha #16

Windows cmd prompt: (You could try the below command directly in windows cmd if you are not comfortable with grep, rm -rf, find, xargs etc., commands in git bash )

Delete .git recursively inside the project folder by the following command in cmd:

FOR /F "tokens=*" %G IN ('DIR /B /AD /S .git') DO RMDIR /S /Q "%G"

comments powered by Disqus