Mac 环境下 git 如何自动补全

2,800 阅读1分钟
原文链接: blog.cyeam.com

安装 bash-completion

brew install bash-completion

将下面代码添加到~/.bash_profile(如果没有该文件,新建一个)。

# git auto completition
if [ -f ~/.git-completion.bash ]; then
  . ~/.git-completion.bash
fi

安装 git-completion.bash

这个文件不能随便安装,网上的教程都是用git参数的master分支,这是不对的,这个版本需要和当前系统安装的git版本对应。

git version

看看自己的版本是什么,我的是2.17.1,就需要用这个版本的脚本。将脚本报存到~/.git-completion.bash里面,然后执行:

source ~/.git-completion.bash
source ~/.bash_profile

这样就可以咯,按下Tab键就可以提示啦。

$ git che
checkout      cherry        cherry-pick

更多阅读:.git-completion.bash producing error on macOS Sierra 10.12.6


原文链接:Mac 环境下 git 如何自动补全,转载请注明来源!