Boldewyn Boldewyn - 4 months ago 35
Git Question

How to convert a normal Git repository to a bare one?

How can I convert a 'normal' Git repository to a bare one?

The main difference seems to be:


  • in the normal git repository you have a
    .git
    folder inside the repository containing all relevant data and all other files build your working copy

  • in a bare Git repository, there is no working copy and the folder (let's call it
    repo.git
    ) contains the actual repository data


Answer

In short: replace the contents of repo with the contents of repo/.git, then tell the repository that it is now a bare repository.

To do this, execute the following commands:

cd repo
mv .git .. && rm -fr *
mv ../.git .
mv .git/* .
rmdir .git

git config --bool core.bare true
cd ..; mv repo repo.git # renaming just for clarity

Note that this is different from doing a git clone --bare to a new location (see below).