首先查看PS1:
echo $PS1
在.bashrc中添加下面修改:
function git_branch {branch="`git branch 2>/dev/null | grep "^\*" | sed -e "s/^\*\ //"`"if [ "${branch}" != "" ];thenif [[ $branch == *"HEAD"* ]];thenbranch="`git rev-parse --short HEAD`"fiecho "($branch)"fi
}export PS1='\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;32m\]$(git_branch)\[\033[00m\]\$'
注意:只要添加\[\033[01;32m\]$(git_branch)就可以显示git分支,其他内容也可以个人喜好修改。