Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git - did init bare in wrong directory

Tags:

git

undo

git-bare

I ran the git --bare init in a wrong directory(in the server). I see the files branches, config, deps etc., in that directory.. How do I undo it?

like image 436
500865 Avatar asked Apr 13 '12 04:04

500865


People also ask

Can you undo git init?

While there is no undo git init command, you can undo its effects by removing the . git/ folder from a project. You should only do this if you are confident in erasing the history of your repository that you have on your local machine.

What does git init bare do?

git . The --bare flag creates a repository that doesn't have a working directory, making it impossible to edit files and commit changes in that repository. You would create a bare repository to git push and git pull from, but never directly commit to it.


2 Answers

Since you performed a '--bare' init, there is no .git directory - instead the normal contents of the .git directory are directly in the parent directory. For example, the place where you did 'git init --bare' looks something like:

$ git --bare init
Initialized empty Git repository in /Users/ebg/test/foo/
$ ls
HEAD        config      hooks/      objects/
branches/   description info/       refs/

to undo this simply perform:

rm -rf HEAD config hooks objects branches description info refs

Of course, be careful if you already had files and directories there with those names.

like image 192
GoZoner Avatar answered Oct 09 '22 15:10

GoZoner


If you did it on directory which wasn't previously set up as git repository, you can just remove .git folder (assuming you're using linux):

rm -rf .git

Otherwise, if directory already contained repository (.git directory), than git init would have no effect (i.e. git log will show the same commits before and after git init).

like image 34
BluesRockAddict Avatar answered Oct 09 '22 15:10

BluesRockAddict