Publishing Git Repositories

Dear Lazyweb,

I’ve been using git for a while for most of my projects, and I love it. It’s fast, powerful, and it’s actually quite simple to use. Whenever I start hacking on something, even if it’s just a little utility that will never see the light of day, I generally initialize a git repo and hack in there.

But my question is, what do I do if I want to make that repository public? I want to create a ‘bare’ repository (e.g. without any working directory files) on a public server that I can push to, and that others can pull from and push to. I would have expected some command like git clone --bare ./local-repo ssh://remote-server/remote-repo, but that doesn’t seem to work. Am I overlooking something obvious?

8 Comments

  1. anholt
    Posted May 29, 2007 at 4:03 pm | Permalink | Reply

    anholt@vonnegut:/home/anholt/mesa% ssh people.freedesktop.org
    anholt@annarchy:/home/anholt% mkdir mesa.git
    anholt@annarchy:/home/anholt% cd mesa.git
    anholt@annarchy:/home/anholt/mesa.git% GIT_DIR=. git-init-db
    anholt@annarchy:/home/anholt/mesa.git% touch git-daemon-export-ok
    anholt@annarchy:/home/anholt/mesa.git% emacs description
    anholt@annarchy:/home/anholt/mesa.git% exit
    anholt@vonnegut:/home/anholt/mesa% git-push git+ssh://people.freedesktop.org/~anholt/mesa master:master

  2. Emmanuele
    Posted May 29, 2007 at 4:15 pm | Permalink | Reply

    don’t forget:

    chmod +x repo.git/hooks/post-update

    so that the index is updated with every push.

  3. Anonymous
    Posted May 29, 2007 at 4:18 pm | Permalink | Reply

    Eric’s way will definitely work, but you almost had the clone right.

    $ git clone –bare $remoterepo $localdir

    I think you just had the last two args reversed.

  4. Jonner
    Posted May 29, 2007 at 4:43 pm | Permalink | Reply

    anonymous: I intentionally reversed the last two arguments of ‘git clone’ because I want to initialize a public remote git repo from my local git repo. Reversing the arguments as you suggest only works if you want to clone a public git repo into a local git repo, which is the opposite of what I’m trying to do.

  5. Jonner
    Posted May 29, 2007 at 4:56 pm | Permalink | Reply

    anholt: thanks, that’s a lot better than the only thing I could figure out, which was essentially:
    scp local-repo remote-server/remote-repo
    mv local-repo local-repo.bak
    git clone remote-server/remote-repo local-repo
    # verify everything’s ok
    rm -rf local-repo.bak

    But it still seems like a lot of manual work. I had assumed there would be a more automated way to do this, but if not, oh well.

  6. rob
    Posted May 29, 2007 at 5:11 pm | Permalink | Reply

    If you’ve got git on the remote machine, then you could replace the scp with a git-clone –bare pointing back at your local repository. The advantage being that it’s a bare repository, and I guess you end up transferring less data.

  7. Anonymous
    Posted May 29, 2007 at 5:49 pm | Permalink | Reply

    http://www.kernel.org/pub/software/scm/git/docs/user-manual.html#public-repositories

  8. Jonner
    Posted May 29, 2007 at 5:57 pm | Permalink | Reply

    Aha! So there *is* some official documentation on the subject. I had looked and looked but couldn’t find anything about it. Thank you very much for that link. This lazyweb thing is pretty impressive :)