Also fixes problems in old git versions with -C option. Fixes #6 and probably fixes #19 as well. (cherry picked from commit fff49436)