How to get the current branch name in Git?

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

    Add it to PS1 using Mac :

    PS1='\W@\u >`[ -d .git ] && git branch | grep  ^*|cut -d" " -f2`> $ '
    

    Before running the command above :

    After running that command :

    Dont worry, if it is not GIT repository , it will not display error because of [-d .git] which checks if .git folder exists or not.

提交回复
热议问题