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?
-
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 Answers
You can just delete .git. Typically:
rm -rf .git
Then, recreate as the right user.

- 4,860
- 1
- 29
- 39

- 278,309
- 50
- 514
- 539
-
9Thanks 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
-
61No, 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
-
2If 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
-
-
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
-
-
-
-
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
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

- 13,746
- 5
- 87
- 117
-
2rmdir /s .git if you already add a remote to force files and subfolders – dpineda Oct 15 '15 at 23:14
-
2I did a git init by accident on a folder in Win7. The rmdir /s .git removed it. – qxotk Oct 17 '15 at 00:15
-
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

- 11,714
- 1
- 86
- 77
In PowerShel this is the way to do it:
Remove-Item ".git" -Force -Recurse
This is the shell the VSC uses.

- 181
- 1
- 7
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!).

- 89
- 1
- 5