Git ad-hoc sharing

I recently found quite a cool way for easy sharing sharing of git code between two machines in a LAN or WLAN (as easy as in mercurial). The following command creates a git alias called “serve” (you only need to run this once so you don’t have to manually call git daemon ... each time):

git config --global alias.serve 'daemon --reuseaddr --base-path=. --export-all --verbose'

Get your IP with ifconfig. After this you can just cd into your code directory, (where the .git dir is) and then run:

git serve

This will host a small git daemon (server) and you can stop it any time with CTRL+C. While still running simply run this from the fetching computer (client):

git clone git://the_server_ip/

You can also run the server in a parent directory and actually serve multiple git repositories. If you do you need to include the relative path information to the .git-dir containing directory on the client side:

git clone git://the_server_ip/your/subdirs/here/

Subsequent calls like git fetch should also work. If the IP changes just change the origin remote’s link.

For more you might want to have a look at these:
http://stackoverflow.com/questions/5817095/what-tools-exist-for-simple-one-off-sharing-of-a-git-repo
http://stackoverflow.com/questions/377213/git-serve-i-would-like-it-that-simple

5 thoughts on “Git ad-hoc sharing

  1. Gunnar Grimnes

    You can also use ssh no?

    In my slightly contrived example this seems to work:
    [cc_bash]git clone git+ssh://localhost/home/ggrimnes/projects/rdflib/rdflib tmp/test[/cc_bash]

    Reply
    1. joern Post author

      Yes, but for this you’d need to create an ssh account for the contributors… (something i don’t want to have on my own computer). So if there’s a shared system where all people can login to it’s maybe the simplest solution to use git via ssh, otherwise this ad-hoc approach is very handy.

      Reply
  2. Marius Gedminas

    Thank you, this alias was very handy for me today (to test my latest code in a VirtualBox VM).

    Any tips for killing the git daemon process? A ‘git stop-serving’ alias would be nifty.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.