Check for .git/HEAD directly, instead of cd'ing into .git first.
Should be faster, less code, and functionality wise the same.