Show just the current branch in Git
问题 I tried looking for a special Git command for this, but I couldn't find one. Is there anything shorter or faster than the following? git branch | awk '/\*/ { print $2; }' 回答1: $ git rev-parse --abbrev-ref HEAD master This should work with Git 1.6.3 or newer. 回答2: In Git 1.8.1 you can use the git symbolic-ref command with the "--short" option: $ git symbolic-ref HEAD refs/heads/develop $ git symbolic-ref --short HEAD develop 回答3: With Git 2.22 (Q2 2019), you will have a simpler approach: git