How to get the current branch name in Git?

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

    If you really want the last branch/tag checked out in detached HEAD state as well.

    git reflog HEAD | grep 'checkout:' | head -1 | rev | cut -d' ' -f1 | rev
    

    Update This is nicer if you have and aren't scared of awk.

    git reflog HEAD | grep 'checkout:' | head -1 | awk '{print $NF}'
    

提交回复
热议问题