Git Repository – How to Convert to Bare Repository

gitgit-baregit-clonegit-non-bare-repositoryversion-control

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 making up 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

Best 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 ../repo.git # renaming just for clarity
cd ..
rm -fr repo
cd repo.git
git config --bool core.bare true

Note that this is different from doing a git clone --bare /path/to/repo to a new location (as described here).

Consider this scenario

  • Your origin had 100 branches
    • You have only checked out 10 of them locally
    • Your bare repo will only have the 10
  • You send the bare repo somewhere
    • It would be missing 90 branches

If that's your intention, that's fine. If you needed a mirror of the remote/origin, this is not the way.

Related Question