How can I get the current branch or tag name for my working copy? I have seen references that indicate rev-parse --abbrev-ref HEAD will give branch name, but t
This command can print name in this priority: branch > tag > commit id
git symbolic-ref --short -q HEAD \
|| git describe --tags --exact-match 2> /dev/null \
|| git rev-parse --short HEAD
Merged @xiaohui-zhang's answer and @thisismydesign's comment. I keep coming back to this question every few months, and this is the answer I end up with, so I thought I'd post it.