How to get the current branch name in Git?

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

    I recommend using any of these two commands.

    git branch | grep -e "^*" | cut -d' ' -f 2

    OR

    git status | sed -n 1p | cut -d' ' -f 3

    OR (more verbose)

    git status -uno -bs| cut -d'#' -f 3 | cut -d . -f 1| sed -e 's/^[ \t]//1'| sed -n 1p

提交回复
热议问题