Turn a directory into a git repository
Create a new (and empty) directory and cd
into it:
mkdir repo
cd repo
Create some files in this directory:
'Hello world' > file.txt
42 > file.num
Turn the directory a repository:
git init
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 *
… and then commit them to the repository:
git commit . -m "Start of new project"
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
Then, their tree structure is compared with
diff -r
:
diff.exe -r repo/.git repo-bare
diff.exe repo/.git/config repo-bare/config -y
The two differences in
.git/config
are:
- The value
bare
(or more accurately core.bare
) is set to to true
in the «ordinary» repository and to false
in the bare repository. Setting core.bare
to true
disables some git commands such as git add
or git merge
)
- The «ordinary» repository has the additonal setting
logallrefupdates
, set to true
, which enables the reflog.