在windows上,如果在git工作目录里,git bash 提示符里会显示当前分支:
在Ubuntu里修改一下,实现同样效果:
cd ~
vim .bashrc
在最后添加:
PS1=""
PS1="$PS1"'\[\033[32m\]' # change to green
PS1="$PS1"'\u@\h ' # user@host<space>
PS1="$PS1"'\[\033[33m\]' # change to yellow
PS1="$PS1"'\w ' # pwd
PS1="$PS1"'\[\033[36m\]' # change color to cyan
PS1="$PS1"'`__git_ps1`' # git branch
PS1="$PS1"'\[\033[0m\]' # change color
PS1="$PS1"'\n' # new line
PS1="$PS1"'$ ' # prompt: always $
效果:
如果提示:bash: __git_ps1: 未找到命令。
可以在前面添加下面语句,试试:
source /usr/share/git-core/contrib/completion/git-prompt.sh