How to get the current branch name in Git?

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

    git branch
    

    should show all the local branches of your repo. The starred branch is your current branch.

    If you want to retrieve only the name of the branch you are on, you can do:

    git rev-parse --abbrev-ref HEAD
    

    or with Git 2.22 and above:

    git branch --show-current
    

提交回复
热议问题