本地切换git分支

  • 修改.bashrc文件:vim .bashrc
  • 将下面的代码放在.bashrc最后面
function parse_git_dirty {

  [[ $(git status 2> /dev/null | tail -n1) != "无文件要提交,干净的工作区" ]] && echo "*"
}
function parse_git_branch {
  git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
}
export PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\W\[\e[1;36m\]$(parse_git_branch)\[\e[0m\]$ '
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
}
  • 保存文件,让修改起作用:source .bashrc
  • 切换分支:git checkout 分支名
  • 如果切换失败:
  1. git fetch
  2.  git checkout  -b 分支名 origin/分支名
发布了61 篇原创文章 · 获赞 11 · 访问量 6474

猜你喜欢

转载自blog.csdn.net/weixin_41449756/article/details/99693317