How to get the current branch name in Git?

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

    I know this is late but on a linux/mac ,from the terminal you can use the following.

    git status | sed -n 1p
    

    Explanation:

    git status -> gets the working tree status
    sed -n 1p -> gets the first line from the status body

    Response to the above command will look as follows:

    "On branch your_branch_name"
    

提交回复
热议问题