Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does running git init twice initialize a repository or reinitialize an existing repo?

Tags:

git

What happens to an existing git repository when you issue git init again?

I created a repository with git init. Created a file, add, commit. Check the status (nothing to commit). Then created another file, check the status and I can see it's untracked as expected.

Then, say by mistake, I run git init again and I get Reinitialise existing Git repository message.

Tried git status, but it shows the same. So what really happens?

Can reinitialising an existing git repository this way be harmful or helpful? Why can we git init inside an existing repository?

like image 793
Mr. L Avatar asked Mar 01 '11 01:03

Mr. L


People also ask

What happens if you run git init twice?

Running git init in an existing repository is safe. It will not overwrite things that are already there. The primary reason for rerunning git init is to pick up newly added templates.

What does git init do to an existing repository?

The git init command creates a new Git repository. It can be used to convert an existing, unversioned project to a Git repository or initialize a new, empty repository. Most other Git commands are not available outside of an initialized repository, so this is usually the first command you'll run in a new project.

Can you git init multiple times?

So yes, navigate into each of the Project A directory and Project B directory and run git init .


3 Answers

It seems safe and should not overwrite anything important.

From the git docs:

Running git init in an existing repository is safe. It will not overwrite things that are already there. The primary reason for rerunning git init is to pick up newly added templates.

like image 61
coreyward Avatar answered Oct 03 '22 11:10

coreyward


It seems safe and should not overwrite anything important.

Quoted from the git init documentation:

Running git init in an existing repository is safe. It will not overwrite things that are already there. The primary reason for rerunning git init is to pick up newly added templates.

like image 42
Greg Hewgill Avatar answered Oct 03 '22 12:10

Greg Hewgill


Since v1.7.5 (b57fb80a7), git init in an existing repo has also allowed moving the .git directory:

The primary reason for rerunning 'git init' is to pick up newly added templates (or to move the repository to another place if --separate-git-dir is given).

'Picking up newly-added templates' means that any templates which have not already been copied from the template directory will now be copied into the existing git directory.

'Moving the repository to another place' means that, if --separate-git-dir points to somewhere else, the existing .git directory will be moved there and replaced by a link.

like image 34
Joe Avatar answered Oct 03 '22 11:10

Joe