编辑~/.bash_profile
添加以下代码
export PS1="${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[01;35m\]:\w\[\033[01;31m\]$\[\033[00m\] "
parse_git_branch () {
while read -r branch; do
[[ $branch = \** ]] && current_branch=${branch#* }
done < <(git branch 2>/dev/null)
[[ $current_branch ]] && printf ' [%s]' "$current_branch"
}
export PS1="${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[01;35m\]:\w\[\033[01;31m\]\$(parse_git_branch)$\[\033[00m\] "
然后保存,这样git就自然高亮了