3

I found a related question below, but can't understand 'pick up newly added templates', and seems this explaination was removed in latest http://git-scm.com/docs/git-init

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

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.

I just don't know what will reinitialize actually do, hope someone can explain it detail, thanks a lot :)

user3620613
  • 151
  • 1
  • 7
  • 1
    The "marked as duplicate" text says "If those answers do not fully address your question, please ask a new question." This question is exactly that: The OP read the duplicate, didn't understand part of the answer, and asked a new question (this one). I'm nominating this for reopening. – ChrisGPT was on strike Jan 26 '15 at 17:00

1 Answers1

2

The same git init documentation has this to say about templates:

Template directory

The template directory contains files and directories that will be copied to the $GIT_DIR after it is created.

The template directory will be one of the following (in order):

  • the argument given with the --template option;

  • the contents of the $GIT_TEMPLATE_DIR environment variable;

  • the init.templatedir configuration variable; or

  • the default template directory: /usr/share/git-core/templates.

The default template directory includes some directory structure, suggested "exclude patterns" (see gitignore[5]), and sample hook files (see githooks[5]).

So if you have manually changed the files in /usr/share/git-core/templates, or possibly upgraded to a new version of Git that came with different templates, reinitializing will copy those new files into an existing repository.

The documentation also suggests another reason for reinitializing:

to move the repository to another place if --separate-git-dir is given

And later:

--separate-git-dir=<git dir>

Instead of initializing the repository as a directory to either $GIT_DIR or ./.git/, create a text file there containing the path to the actual repository. This file acts as filesystem-agnostic Git symbolic link to the repository.

If this is reinitialization, the repository will be moved to the specified path.

Community
  • 1
  • 1
ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257