Show just the current branch in Git

I tried looking for a special git command for this but couldn't find one. Can anyone suggest anything shorter or faster than:

git branch | awk '/*/ { print $2; }'

$ git rev-parse --abbrev-ref HEAD
master

这应该适用于Git 1.6.3或更新的版本。


(I can't add comments to answers yet, so)

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

You may be interested in the output of

git symbolic-ref HEAD

In particular, depending on your needs and layout you may wish to do

basename $(git symbolic-ref HEAD)

or

git symbolic-ref HEAD | cut -d/ -f3-

and then again there is the .git/HEAD file which may also be of interest for you.

链接地址: http://www.djcxy.com/p/3286.html

上一篇: 如何以编程方式确定当前签出的Git分支

下一篇: 只显示Git中的当前分支