How to get the current branch name in Git?

后端 未结 30 2712
清酒与你
清酒与你 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:13

    Well simple enough, I got it in a one liner (bash)

    git branch | sed -n '/\* /s///p'
    

    (credit: Limited Atonement)

    And while I am there, the one liner to get the remote tracking branch (if any)

    git rev-parse --symbolic-full-name --abbrev-ref @{u}
    

提交回复
热议问题