tags:

views:

70

answers:

2

I would like to make a repo into a bare repo so people can push to it with out big nasty warnings. I could delete it and clone it again... but perhaps there is a more elegant way?

+4  A: 

It's probably best to just delete and clone again. Example:

mv old_git_repo/ /tmp/
git clone --bare /tmp/old_git_repo/  new_git_repo/

You could also just remove the working files and promote .git/* to .. However, you'd also need to add bare = true and remove logallrefupdates = true in the new bare config's [core] section (formerly .git/config. You could make a script to do this automatically if you like.

Edit: You mentioned in a comment that this was cloned from svn, so a new clone will take a long time. But - don't clone from svn! Just clone from the new git repo, and it will be git -> git, which will be fast. Or, see my note above about just moving the files.

Peter
I second the recommendation to clone (git->git, not svn->git, of course). It's always best to avoid mucking around inside `.git` if you can, even though this is a pretty simple manipulation.
Jefromi
I get a "Too many arguments" error when I run `git clone --bare /path/to/existing_repo /path/to/new_repo`. I've also tried it with a trailing `/.git` on the first argument.
James A. Rosen
A: 

A bare repository is simply a .git directory without the working directory. So you can simply replace the project dir with the contents of .git and it should work:

mv /path/to/projectdir /path/to/projectdir.old
mv /path/to/projectdir.old/.git /path/to/projectdir
rm -rf /path/to/projectdir
gyim
You should also set the `core.bare` configuration option to a true value. But, it is probably best to just use `git clone --bare`.
Chris Johnsen
You're right, a "git config core.bare 1" command is also needed. Thanks for the correction!
gyim
Shouldn't the third line be `rm -rf /path/to/projectdir.old`? You're keeping the working directory and throwing away the git database.
James A. Rosen