您的位置:首页 > 运维架构 > Linux

linux 命令行终端显示git 当前所在分支

2018-03-10 16:27 726 查看
在 .bashrc 里面添加


#show the current git branch
find_git_branch () {
local dir=. head
until [ "$dir" -ef / ]; do
if [ -f "$dir/.git/HEAD" ]; then
head=$(< "$dir/.git/HEAD")
if [[ $head = ref:\ refs/heads/* ]]; then
git_branch="(*${head#*/*/})"
elif [[ $head != '' ]]; then
git_branch="(*(detached))"
else
git_branch="(*(unknow))"
fi
return
fi
dir="../$dir"
done
git_branch=''
}

PROMPT_COMMAND="find_git_branch; $PROMPT_COMMAND"
PS1="\u@\h:\w\[\033[0;32m\]\$git_branch\[\033[0m\] \$ "
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  linux git