Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 397
Boldewyn Avatar asked Feb 04 '10 13:02

Boldewyn


People also ask

What is a bare git repo?

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.


2 Answers

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).

like image 57
Jörg W Mittag Avatar answered Sep 20 '22 17:09

Jörg W Mittag


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.

like image 36
jonescb Avatar answered Sep 22 '22 17:09

jonescb