Make git handling more robust (Closes #21)

Use "git fetch" + "git checkout" instead of "git pull", because "pull" fails on detached HEADs.

Also includes a bit of unrelated robustness improvements.