Use git show-ref instead of git branch for better future-proofness.

Based on original patch by Anrs Hu.