460

I can't find the command. I tried Googling "git 'delete a repository'".

Coleman
  • 565
  • 7
  • 15
Victor
  • 23,172
  • 30
  • 86
  • 125
  • 1
    This [link](https://community.atlassian.com/t5/Sourcetree-questions/How-to-remove-repository-from-local-without-removing-it-from/qaq-p/186628) might help. – zyy Apr 03 '19 at 17:36

4 Answers4

658

Delete the .git directory in the root-directory of your repository if you only want to delete the git-related information (branches, versions).

If you want to delete everything (git-data, code, etc), just delete the whole directory.

.git directories are hidden by default, so you'll need to be able to view hidden files to delete it.

Sinister Beard
  • 3,570
  • 12
  • 59
  • 95
344

To piggyback on rkj's answer, to avoid endless prompts (and force the command recursively), enter the following into the command line, within the project folder:

$ rm -rf .git

Or to delete .gitignore and .gitmodules if any (via @aragaer):

$ rm -rf .git*

Then from the same ex-repository folder, to see if hidden folder .git is still there:

$ ls -lah

If it's not, then congratulations, you've deleted your local git repo, but not a remote one if you had it. You can delete GitHub repo on their site (github.com).

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

defaults write com.apple.finder AppleShowAllFiles TRUE
killall Finder

Source: http://lifehacker.com/188892/show-hidden-files-in-finder.

Community
  • 1
  • 1
Azat
  • 3,754
  • 2
  • 15
  • 13
  • 6
    It's not only to avoid prompts, rm -rf was necessary for me otherwise rm would not delete files and complain: rm: cannot remove `.git/objects/pack': Directory not empty – Étienne Apr 24 '13 at 13:38
  • 3
    Yes, -r is for recursive and -f is for force. So you are forcing and doing recursive deletion. – Azat May 07 '13 at 21:53
  • 2
    I'd actually suggest deleting `.git*` to also remove `.gitignore` and `.gitmodules` if any. – aragaer May 07 '13 at 22:14
  • Thanks) its work great ,for windows in project folder run rm -rf .git – Qui-Gon Jinn Nov 28 '19 at 05:14
  • " -r is for recursive" that means you tell the guy to delete the entire repo struct just because he created one in a wrong place higher in the directory structure – Leon May 30 '20 at 17:25
63

In the repository directory you remove the directory named .git and that's all :). On Un*x it is hidden, so you might not see it from file browser, but

cd repository-path/
rm -r .git

should do the trick.

rkj
  • 8,787
  • 2
  • 29
  • 35
6

That's right, if you're on a mac(unix) you won't see .git in finder(the file browser). You can follow the directions above to delete and there are git commands that allow you to delete files as well(they are sometimes difficult to work with and learn, for example: on making a 'git rm -r ' command you might be prompted with a .git/ not found. Here is the git command specs:

usage: git rm [options] [--] ...

-n, --dry-run         dry run
-q, --quiet           do not list removed files
--cached              only remove from the index
-f, --force           override the up-to-date check
-r                    allow recursive removal
--ignore-unmatch      exit with a zero status even if nothing matched

When I had to do this, deleting the objects and refs didn't matter. After I deleted the other files in the .git, I initialized a git repo with 'git init' and it created an empty repo.

LucianNovo
  • 360
  • 5
  • 14
  • 1
    That's not 100% true. I'm on Mac OS X and I can see `.git` and other hidden/system folder easily (e.g., `.DS_Store`). All you need to do is to configure Finder. Here is how: http://lifehacker.com/188892/show-hidden-files-in-finder. `defaults write com.apple.finder AppleShowAllFiles TRUE` and then `killall Finder`. – Azat May 07 '13 at 21:57
  • Yes that's right, you can configure finder to show hidden files, as well as you can configure editors to show hidden folders. The lesson here is that everything that begins with a '.' is a usually a hidden folder/file. – LucianNovo May 08 '13 at 06:13
  • 1
    Actually, for OS X you can use the key combination Shift-Command-[period] to show or hide hidden files or directories - much easier than entering those commands into terminal! – TheOnlyMrCat Jul 19 '18 at 06:31