Yarin
Yarin

Reputation: 183919

Is there a command to undo git init?

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?

Upvotes: 1023

Views: 816755

Answers (7)

Poonam Bhatt
Poonam Bhatt

Reputation: 10332

I have by mistake run the git init command on the root folder.

So I removed the .git folder with rm -r .git/.

And it worked best for me

Upvotes: 0

Matthew Flaschen
Matthew Flaschen

Reputation: 285017

If you just inited it, you can just delete .git.

Typically:

rm -rf .git

Then, recreate as the right user.

EDIT: NOTE: This deletes the entire git repository (including all commit history, etc.). On a newly-created repository, there is no history yet.

Upvotes: 1861

Rui Monteiro
Rui Monteiro

Reputation: 329

In PowerShel this is the way to do it:

Remove-Item ".git" -Force -Recurse

This is the shell the VSC uses.

Upvotes: 14

Luca C.
Luca C.

Reputation: 12594

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

Upvotes: 15

domdaviesdev
domdaviesdev

Reputation: 89

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

Upvotes: 5

LF-DevJourney
LF-DevJourney

Reputation: 28554

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

Upvotes: 9

wordsforthewise
wordsforthewise

Reputation: 15857

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

Upvotes: 82

Related Questions