Support empty git repos

This fixes various issues for the case when an empty repository was throwing an error on committing  changes.

I was able to clone a empty repo, do some changes, create and switch branches and finally push the first commit to the repo.

TODO: the empty repo still appear to be dirty as if there are un-committed changes. Looking into it.

Fixes #3150 
@devoncarew 
indent