In a truly collaborative development environment in the same physical space (such as railscamp, rubyconf, etc) wouldn’t it be cool to just push and pull changesets between laptops, without the need for any central server or network?
This was the exact setup I waned to shoot for for railscamp, but geting it set up on people’s machines was too much—a central SVN seemed to work much better. It did however demonstrate it working, pushing, pulling and merging between four repositories on four laptops.
If you are going offline it may also be worth perusing fellow railscamper Dr Nic’s article showing us how to mirror an SVN repo in git.
Enable web sharing (i.e. Apache 2)
Firstly make sure web sharing is enabled (System Preferences > Sharing).
By default it uses ~/Sites to serve your files to http://localhost/~yourusername/
In my case I wanted to use ~/www instead of ~/Sites (all my source files live is ~/Sites), so I created a ~/www directory and changed /etc/apache2/users/tlucas.conf accordingly:
$ mkdir ~/www
$ mate /etc/apache2/users/tlucas.conf
<Directory "/Users/tlucas/www/">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
Alternatively you could change /etc/apache2/extra/httpd-userdir.conf to use www instead of Sites as the default user directory.
Restart apache2, put in a test file and see what happens:
$ sudo apachectl restart
$ echo "Test" > ~/www/index.html
$ curl http://localhost/~tlucas/
Test
There’s little point progressing unless you get this working.
Create the public repository
Initialising the public repository is exactly the same as setting up a new remote repository with the addition of a simple step.
Remote repositories can not only be remote servers, but can be other repositories on the same filesystem. Git’s definition “remote” is “a different git repository”.
We set up a new bare git repository like you’ve seen before:
$ cd ~/www
$ mkdir -p git/myapp.git
$ cd git/myapp.git
$ git --bare init
Add then add it as a remote repository and push to it:
$ cd ~/Sites/myapp
$ git remote add public /Users/tlucas/www/git/myapp.git
$ git push public master
Enable sharing via HTTP
Deep within the git user manual are the two operations you’ll need to do to your public repository so that other people are able to access it via HTTP:
$ cd ~/www/git/myapp.git
$ git --bare update-server-info
$ chmod a+x hooks/post-update
Test the public repository from another machine
Jump onto another machine and have a stab at cloning the repository via HTTP.
$ git clone http://tim.local/~tlucas/git/myapp.git
If all is well you should now have a local clone of the repository. Fire up gitk to browse through all the revision history.
Archived comments
Comments were previously allowed on articles. Though no new comments are being accepted you can see the old comments below.
-
Too easy! Thanks for the clear instructions.
I banged my head against this until I realized that the “
-bare init” or “-bare clone” is really necessary. You can’t just cp an existing repository and expect to serve it up. -
Yeah I got sick of just fumbling around and decided to figure out what the deal was once and for all. So confusing at first the whole bare thing.
