Search notes:

Git: Create a bare repository from a repository

Creating a bare repository from a repository (let alone from a directory) is not as simple as it should be (but I am used to such problems with git). This Stackoverflow answer was very helpful to me when I tried to figure out how to achieve that.
First, we need to create a repsitory using git init.
git init -q repo
Github repository about-git, path: /repository/bare/create-from-repo/create-repo
We then need to add some content (here: a file and a directory with a file) to the repository, add the content (git add) and commit it:
pushd repo > /dev/null

mkdir dir

cat << EOF > dir/lorem-ibsum.txt
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Aenean commodo ligula eget dolor. Aenean massa. Cum sociis
natoque penatibus et magnis dis parturient montes,
nascetur ridiculus mus.
EOF

cat << EOF > file.txt
It was the best of times, it was the worst of times, it was the age of wisdom,
it was the age of foolishness, it was the epoch of belief, it was the epoch of
incredulity, it was the season of light, it was the season of darkness, it was
the spring of hope, it was the winter of despair
EOF

git add .
git commit -q -m 'init repository'

popd > /dev/null
Github repository about-git, path: /repository/bare/create-from-repo/add-content
Copying the repository directory repo/.git to repo.git is the first step for the new directory (repo.git) to be a bare repository.
The original repository (repo) is not needed anymore, it can be deleted:
cp -r repo/.git repo.git

rm -rf repo
Github repository about-git, path: /repository/bare/create-from-repo/copy-git-directory
The second step is to set core.bare to true:
pushd repo.git > /dev/null
git config --bool core.bare true
popd > /dev/null
Github repository about-git, path: /repository/bare/create-from-repo/config-bare
Finally, we can test if everything worked by cloning the bare repository:
git clone -q repo.git repo.cloned

pushd repo.cloned > /dev/null
tree

git log --format=oneline

popd > /dev/null
Github repository about-git, path: /repository/bare/create-from-repo/clone-new-repo

Index