How to convert a normal Git repository to a bare one?
Solution 1:
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
to a new location (see below).
Solution 2:
Your method looks like it would work; the file structure of a bare repository is just what is inside the .git directory. But I don't know if any of the files are actually changed, so if that fails, you can just do
git clone --bare /path/to/repo
You'll probably need to do it in a different directory to avoid a name conflict, and then you can just move it back to where you want. And you may need to change the config file to point to wherever your origin repo is.
Solution 3:
I think the following link would be helpful
GitFaq: How do I make existing non-bare repository bare?
$ mv repo/.git repo.git
$ git --git-dir=repo.git config core.bare true
$ rm -rf repo
Solution 4:
Unless you specifically want or need to twiddle bits on the filesystem, it really is dead simple to create a bare version of a non-bare repository (mentioned in several other posts here). It’s part of git’s core functionality:
git clone --bare existing_repo_path bare_repo_path