How to get the current branch name in Git?

后端 未结 30 3128
清酒与你
清酒与你 2020-11-22 07:47

I\'m from a Subversion background and, when I had a branch, I knew what I was working on with \"These working files point to this branch\".

But with Git I\'m not sur

30条回答
  •  自闭症患者
    2020-11-22 08:24

    Found a command line solution of the same length as Oliver Refalo's, using good ol' awk:

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

    awk reads that as "do the stuff in {} on lines matching the regex". By default it assumes whitespace-delimited fields, so you print the second. If you can assume that only the line with your branch has the *, you can drop the ^. Ah, bash golf!

提交回复
热议问题