safely check if inside of a git working tree

Some git commands (branch detection) will fail when
inside a bare git repository.