Search notes:

git init

git init creates an empty git repository or reinitializes an existing one.
Without the --bare option, the created repository is called a working directory.
The main purpose of executing git init in an existing repository is to

Turn a directory into a git repository

Create a new (and empty) directory and cd into it:
mkdir repo
cd    repo
Github repository about-git, path: /commands/init/in-repo/create-dir.ps1
Create some files in this directory:
'Hello world' > file.txt
 42           > file.num
Github repository about-git, path: /commands/init/in-repo/create-files.ps1
Turn the directory a repository:
git init
Github repository about-git, path: /commands/init/in-repo/init.ps1
The repository is stored in a sub-directory named .git.
git init did not add the files in the directory, let alone commit, to the repository.
So, add the files to the index
git add *
Github repository about-git, path: /commands/init/in-repo/add.ps1
… and then commit them to the repository:
git commit . -m "Start of new project"
Github repository about-git, path: /commands/init/in-repo/commit.ps1
Destroy the repository:
cd ..
rmdir -recurse --force repo

git init <directory>

When executing git init, a directory name can be specified:
git init funProject
This will create the directory funProject and the repository (the .git directory) in that directory.

Initializing an ordinary repository vs. a bare repository

The only difference between a freshly created «ordinary» and bare repository is the content of the repository's config file, which is demonstrated here.
First, the two repositories are created:
git   init          --quiet  repo
git   init  --bare  --quiet  repo-bare
Github repository about-git, path: /commands/init/vs-bare/init-repos.ps1
Then, their tree structure is compared with diff -r:
diff.exe -r  repo/.git  repo-bare
Github repository about-git, path: /commands/init/vs-bare/diff-r.ps1
It turns out that only .git/config is diffent.
diff.exe repo/.git/config  repo-bare/config  -y
Github repository about-git, path: /commands/init/vs-bare/diff-config.ps1
The two differences in .git/config are:

See also

git init-db is a synonym for git init.
Executing git init installs some sample hook-scripts under .git/hooks. These scripts come with the suffix .sample which needs to be removed to make them operational.
git commands
/usr/share/git-core/templates

Index