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
What is a bare repository? A bare repository is the same as default, but no commits can be made in a bare repository. The changes made in projects cannot be tracked by a bare repository as it doesn't have a working tree. A working tree is a directory in which all the project files/sub-directories reside.
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With