Patch Set 1: I would prefer that you didn't submit this

I believe bare repositories typically also define HEAD, just semantics are different: for bare repository they point to the default branch which is the one a local branch is created for when cloning the repository

I think instead you should check if the config parameter core.bare is true.