CakePHP, one of the projects I work with, uses Git. I’ve always ever used Subversion personally, so it seems time to get with the program here by setting up a Git repository. Well, Git is a different animal, enabling a distributed workflow, and you don’t have to use it like you use Subversion, but that’s another story.
In short, we’ll create a bare repository to be hosted via HTTP/DAV on Apache.
Here are the steps I took on Ubuntu 9.10. I had Git installed and an existing Apache server up and running but didn’t have DAV configured.
Start by creating a bare repository by cloning an existing git project like so:
git clone --bare /path/to/git/project /path/to/new/repo.git
Enable access to the repository:
Copy the repository into place to be served by Apache:
mv /path/to/new/repo.git /var/www/repo.git
Also don’t forget to do this, otherwise gitting stuff doesn’t work:
cd /var/www/repo.git git --bare update-server-info
If you haven’t set up the Dav module for Apache, you’ll need to if you want to push stuff, etc. Here’s how:
# enable the dav module + dependencies a2enmod dav_fs
/etc/apache2/sites-available/default, add a Directory container in the VirtualHost:
<Directory /path/to/repo.git> Dav On Allow from all </Directory>
Restart the server…
…and test it out.
I hadn’t set up DAV properly and spent an hour figuring out this error when I tried a
error: Cannot access URL http://localhost/atsui/taspa.git/, return code 22 error: failed to push some refs to 'http://localhost/atsui/taspa.git'
It confused me because I could do
git clone from the server without trouble, so I didn’t quite know what to think. Checking the log is always a wise thing to do. From Apache’s
18.104.22.168 - - [19/Jan/2010:09:43:49 -0800] "PROPFIND /atsui/taspa.git/ HTTP/ 1.1" 405 565 "-" "git/22.214.171.124"
The 405 HTTP code translates to “Method not allowed”. Although I had enabled the DAV module, I didn’t have DAV enabled on that directory. Follow the steps above and you shouldn’t see the problem.
If you notice, the directory is configured to allow git read/write access to everyone. An extension to this guide might be to set up user authentication on Apache. Or if you’re into SSH and keys, you can set that up, too. I’m not so familiar with that so I might try that out as well.
Git’s got some stuff to get used to. I only found out about bare repositories after trying to push changes to a repository that I cloned from, which is bad because it’s like shoving changes into someone else’s workspace and confusing Git in the process. I’ll have to read more about this workflow. Do people just pull stuff that they like from others? Or should it be that people use Git to create patches and give it to someone to put together?
Here’s the useful references I used for this write-up.
Here’s where I found out how to create a Git repository to use in the Subversion repository style.
Details on how to get the Git repository onto Apache
Lots of alternative setups and considerations for choosing specific ones.