MacOS

$ vim ~/.bash_profile

写入以下内容:

# Git branch in prompt
parse_git_branch() {
    git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}

export PS1="\u@\h \W\[\033[32m\]\$(parse_git_branch)\[\033[00m\] $ "

加载配置:

source ~/.bash_profile

就可以看到效果。