29

I already created a repository. Can I make it a bare type or shall I start over?

mrblah
  • 88,033
  • 134
  • 292
  • 404

3 Answers3

41

According to the FAQ, conversion from non-bare to bare can be done in two ways. The best one:

$ git clone --bare -l repo repo.git
$ rm -rf repo

To create a bare repository from scratch:

$ mkdir repo.git
$ cd repo.git
$ git --bare init
Arbo
  • 95
  • 8
Jørn Schou-Rode
  • 35,883
  • 13
  • 81
  • 120
  • Why is the first method "easier"? The second method seems both safer *and* easier (you don't need the renames to get the same result as the first method, just `git clone --bare repo` followed by `rm -rf repo` will do). – Dan Moulding Nov 24 '09 at 14:30
  • @Dan is right, and I have modified my answer to only contain the safe *and* easy approach. With the version of git on my box (1.5.6.5), I still need to provide the target directory when calling git-clone, though. – Jørn Schou-Rode Nov 24 '09 at 15:04
  • 2
    Doesn't `git clone` set the `origin` remote to the one cloned from? In this case to `./repo`, which you `rm`'d... – Boldewyn Feb 04 '10 at 19:12
  • 6
    The [FAQ](https://git.wiki.kernel.org/index.php/GitFaq#HowdoImakeexistingnon-barerepositorybare.3F) now suggests `git clone --bare -l`. The `-l` asks for hardlinks, which makes this faster. Although note that by using git clone you lose config settings/remotes, so beware. – Marius Gedminas Dec 24 '10 at 01:28
  • @Marius: Thanks for the heads-up. I have an `-l` and updated the FAQ link to reflect URL changes. – Jørn Schou-Rode Dec 31 '10 at 08:04
  • 1
    Note that hardlinking with -l will save time and space during cloning *and* prevent you from loosing data if you later remove the non-bare repo, as the files are still linked by the bare one. Of course it only works if your file system supports hard links.. – ggll Feb 26 '14 at 10:28
20

Just move the .git folder away from the working copy.

mv /var/git/repo/repo/.git /var/git/repos/repo.git

You might want to follow that up with a

git config --bool core.bare true

in that repository, just in case git complains about something not being right.

FractalSpace
  • 4,833
  • 2
  • 36
  • 44
Bombe
  • 74,913
  • 20
  • 118
  • 125
5
git clone --bare repo

This will give you a new bare version of repo named repo.git. Easy, no?

Dan Moulding
  • 183,296
  • 21
  • 89
  • 97