pesartain.com

where I remind myself what I've accomplished.

Slaving Git to the Web

What started out as a search around the web for ways of maintaining local development code and production code, and keeping them synchronised landed me on Joe Maller's site, with an excellent writeup of using Git for the process (a web-focussed git workflow).

While the idea itself was sound, there were a few stumbling blocks in my implementation of it.

Firstly, I needed git on the server, which Joe kindly provided instructions for (how to install git on a shared host). A little ingenuity by wrapping each of the commands in a php exec() call made it possible to build and run git on my shared host.

Even with git now on the server, without control over Apache modules (WebDAV) or SSH access, I can't remote push to the shared web host, I can only pull. Enter sharedgit.php, a two file solution that provides a web-based frontend to exec() git calls and provide an interface to any git repositories located on the shared host.

At the local end, I have a combined file- and web-server as well as multiple development machines. Only the fileserver is viewable from the shared host, so I need to be able to pull and push to the fileserver and maintain that as a centralised distribution point. Since we don't need to deploy the code, just the repo, on the fileserver, we can use git's bare repo feature. Toolman Tim to the rescue with a nice write up here about bare repos.

On the remote side, prepare the bare repo:

~# mkdir project.git
~# cd project.git
~# git --bare init
~# git --bare update-server-info
~# mv hooks/post-update.sample hooks/post-update
~# chmod +x hooks/post-update

Take a local repo on the development machine and hook it up to the remote bare repo on the with:

~# git remote add server ssh://<address>/project.git

To ensure the fileserver's copy will always be up to date, add a post-commit hook in the development repo of:

~# echo -n "exec git push server master" > hooks/post-commit
~# chmod +x hooks/post-commit

Now I can edit some code on a development machine, and on commit that change is reflected straight into the fileserver. A button push later and I've pulled that change from the fileserver into the shared host.

The git magic documentation was invaluable in this enterprise, and of course the git documentation had some handy tips.

Who am I? I answer to Piete or Pieter and I try to be more than just my job title.

Browse my blog, read about me, or listen to my music.