Fixing up the git support

The previous git support was quite fragile, so I've given it a bit of a tidy.