The main gitshed functionality.

Pulls together code from previous commits.

The main() wrapper, BUILD files etc. will follow shortly.
The code after here should either be in an else after the `except:` or just after the try block. Catching KeyError in arbitrary code can lead to really confusing error messages