I already created a repository. Can I make it a bare type or shall I start over?
When creating a git repository that will be on the server, can I convert it to a bare repository? [duplicate]
Asked Answered
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
@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. –
Tosha
Doesn't
git clone
set the origin
remote to the one cloned from? In this case to ./repo
, which you rm
'd... –
Leviticus The FAQ 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. –
Creak @Marius: Thanks for the heads-up. I have an
-l
and updated the FAQ link to reflect URL changes. –
Tosha 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.. –
Research
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.
how do I create a bare repo rigth from the start? –
Econometrics
Pass the
--bare
flag to git
: $ mkdir myrepo.git && cd myrepo.git && git --bare init
–
Eyesore Or just
git init --bare myrepo.git
–
Provenience Note that being able to do
git init --bare
as an alternative to git --bare init
came in in v1.5.6 ~Jun 08. –
Myrtlemyrvyn git clone --bare repo
This will give you a new bare version of repo
named repo.git
. Easy, no?
© 2022 - 2024 — McMap. All rights reserved.
git clone --bare repo
followed byrm -rf repo
will do). – Freehanded