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.
git init creates a
.git subdirectory in the current working directory, which contains all of the necessary Git metadata for the new repository. This metadata includes subdirectories for objects, refs, and template files. A
HEAD file is also created which points to the currently checked out commit.
Aside from the
.git directory, in the root directory of the project, an existing project remains unaltered (unlike SVN, Git doesn't require a
.git subdirectory in every subdirectory).
git init will initialize the Git configuration to the
.git subdirectory path. The subdirectory path can be modified and customized if you would like it to live elsewhere. You can set the
$GIT_DIR environment variable to a custom path and
git init will initialize the Git configuration files there. Additionally you can pass the
--separate-git-dir argument for the same result. A common use case for a separate
.git subdirectory is to keep your system configuration "dotfiles" (
.vimrc, etc.) in the home directory while keeping the
.git folder elsewhere.