Just the name of the current branch if on a branch, but if detached then print the current commit id:
git symbolic-ref --short HEAD 2>/dev/null || git rev-parse --short HEAD
The first part will return an error if detached, and the second part will always print the current commit id.