1 打開終端,輸入 cd ~
2 vi .bashrc ?然后在出現(xiàn)的文件中添加下面的代碼
function git_branch {
? branch="`git branch 2>/dev/null | grep "^\*" | sed -e "s/^\*\ //"`"
? if [ "${branch}" != "" ];then
? ? ? if [ "${branch}" = "(no branch)" ];then
? ? ? ? ? branch="(`git rev-parse --short HEAD`...)"
? ? ? fi
? ? ? echo " ($branch)"
? fi
}
export PS1='\u@\h \[\033[01;36m\]\W\[\033[01;32m\]$(git_branch)\[\033[00m\] \$ '
3 :wq 保存退出
4 ?source ./.bashrc
5 ?echo "[ -r ~/.bashrc ] && source ~/.bashrc" >> .bash_profile
這就設置好了还最,打開終端進入工程所在的目錄杠巡,會自動顯示當前分支巍棱。