The main gitshed functionality.

Pulls together code from previous commits.

The main() wrapper, BUILD files etc. will follow shortly.
The code up to this point in the function would be easier to read as code constructing a list of strings to run rather than producing a string which is then shlex'd