979

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?

2

6 Answers 6

1796

You can just delete .git. Typically:

rm -rf .git

Then, recreate as the right user.

13
  • 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 9, 2010 at 12:23
  • 61
    No, you can always just remove the entire .git subdirectory with no ill effects.
    – mskfisher
    Jul 9, 2010 at 12:26
  • 93
    @mskfisher: No ill effects besides your repository being gone, that is!
    – Cascabel
    Jul 9, 2010 at 15:51
  • 13
    I think this does not work in windows. For windows rmdir /s .git
    – Yubaraj
    Jan 28, 2016 at 5:28
  • 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, 2016 at 17:05
78

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

3
  • 2
    rmdir /s .git if you already add a remote to force files and subfolders
    – dpineda
    Oct 15, 2015 at 23:14
  • 2
    I did a git init by accident on a folder in Win7. The rmdir /s .git removed it.
    – qxotk
    Oct 17, 2015 at 0:15
  • confirmed works in windows10 with VS code. thanks.
    – D.L
    May 5, 2021 at 18:46
14

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

10

In PowerShel this is the way to do it:

Remove-Item ".git" -Force -Recurse

This is the shell the VSC uses.

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

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.