How to get the current branch name in Git?

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

    You can permanently set up your bash output to show your git-branch name. It is very handy when you work with different branches, no need to type $ git status all the time. Github repo git-aware-prompt .

    Open your terminal (ctrl-alt-t) and enter the commands

    mkdir ~/.bash
    cd ~/.bash
    git clone git://github.com/jimeh/git-aware-prompt.git
    

    Edit your .bashrc with sudo nano ~/.bashrc command (for Ubuntu) and add the following to the top:

    export GITAWAREPROMPT=~/.bash/git-aware-prompt
    source "${GITAWAREPROMPT}/main.sh"
    

    Then paste the code

    export PS1="\${debian_chroot:+(\$debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\] \[$txtcyn\]\$git_branch\[$txtred\]\$git_dirty\[$txtrst\]\$ "
    

    at the end of the same file you pasted the installation code into earlier. This will give you the colorized output:

提交回复
热议问题