965

I just Git init'ed a repos with a wrong user, and want to undo it. Is there any command for this? Do I actually have to go in and edit the .git directory?

jww
  • 97,681
  • 90
  • 411
  • 885
Yarin
  • 173,523
  • 149
  • 402
  • 512
  • 1
    [How to fully delete a git repository created with init?](https://stackoverflow.com/q/1213430/6521116) – LF00 Jun 07 '17 at 09:39
  • Does this answer your question? [How to fully delete a git repository created with init?](https://stackoverflow.com/questions/1213430/how-to-fully-delete-a-git-repository-created-with-init) – IMSoP Mar 03 '22 at 08:44

6 Answers6

1773

You can just delete .git. Typically:

rm -rf .git

Then, recreate as the right user.

giraffesyo
  • 4,860
  • 1
  • 29
  • 39
Matthew Flaschen
  • 278,309
  • 50
  • 514
  • 539
  • 9
    Thanks Mathew, but can you expound on "if you just inited it"- what if i've done some stuff since, a few commits etc, would simply removing this be a problem? – Yarin Jul 09 '10 at 12:23
  • 61
    No, you can always just remove the entire `.git` subdirectory with no ill effects. – mskfisher Jul 09 '10 at 12:26
  • 93
    @mskfisher: No ill effects besides your repository being gone, that is! – Cascabel Jul 09 '10 at 15:51
  • 2
    If you init a sub git directory in your current git directory, don't do the command above. – Zen Feb 05 '15 at 11:04
  • 13
    I think this does not work in windows. For windows `rmdir /s .git` – Yubaraj Jan 28 '16 at 05:28
  • Not working. It says .git\refs\heads - Access is denied. – cosmoloc May 12 '16 at 14:10
  • 4
    @Zen, why not? Say you accidentally initialized your workspace folder with git and all subdirectories are git repos, is there any harm in removing `.git` from the workspace folder? – Srini May 12 '16 at 17:05
  • This helped me, thank you! I was looking all over to find the answer to this problem. [This article](https://kolosek.com/git-commands-tutorial-part2/) also helped me to get a better understanding of how git commands work as well. – Nesha Zoric May 07 '18 at 12:20
  • Found out that this command must be executed on cmd.exe, not on Powershell. Otherwise you get a `Remove-Item : A positional parameter cannot be found that accepts argument '.\.git'.` error. – Sander Vanden Hautte Jun 20 '19 at 12:54
  • Cross platform if you have npm: `npx rimraf .git` – David Callanan Feb 14 '20 at 19:49
  • running `git remote remove origin` after this answer worked best for me – David Dec 10 '21 at 04:44
  • In powershell is ```rm -r -Force .git``` – Said Torres Sep 28 '22 at 16:46
  • don't run this command if you accidentally run `git init` on a folder you already git initialized before: https://stackoverflow.com/questions/19397888/how-to-undo-misoperation-of-reinitialized-existing-git-repository – Tms91 Mar 21 '23 at 16:37
77

In windows, type rmdir .git or rmdir /s .git if the .git folder has subfolders.

If your git shell isn't setup with proper administrative rights (i.e. it denies you when you try to rmdir), you can open a command prompt (possibly as administrator--hit the windows key, type 'cmd', right click 'command prompt' and select 'run as administrator) and try the same commands.

rd is an alternative form of the rmdir command. http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/rmdir.mspx?mfr=true

wordsforthewise
  • 13,746
  • 5
  • 87
  • 117
13

remove the .git folder in your project root folder

if you installed submodules and want to remove their git, also remove .git from submodules folders

Luca C.
  • 11,714
  • 1
  • 86
  • 77
10

In PowerShel this is the way to do it:

Remove-Item ".git" -Force -Recurse

This is the shell the VSC uses.

Rui Monteiro
  • 181
  • 1
  • 7
9

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

This post well show you how to find the hide .git file on Windows, Mac OSX, Ubuntu

LF00
  • 27,015
  • 29
  • 156
  • 295
5

I'm running Windows 7 with git bash console. The above commands wouldn't work for me.

So I did it via Windows Explorer. I checked show hidden files, went to my projects directory and manually deleted the .git folder. Then back in the command line I checked by running git status.

Which returned...

fatal: Not a git repository (or any of the parent directories): .git

Which is exactly the result I wanted. It returned that the directory is not a git repository (anymore!).

domdaviesdev
  • 89
  • 1
  • 5