Mac 下 git 命令自动补全
一. 安装 bash-completion
brew install bash-completion
安装成功后提示:
==> Caveats Add the following line to your ~/.bash_profile: [ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion Bash completion has been installed to: /usr/local/etc/bash_completion.d
接下来按照提示,将下面语句放到~/.bash_profile
[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion
二. 下载 git-completion.bash
访问 选择 branch 为你 git 版本的分支,比如我的:
$ git version git version 2.13.5 (Apple Git-94)
注意: 这里如果不使用相匹配的版本,会导致后面 git 补全命令时报错 Unknown option:
好,选好分支后,找到 contrib/completion/git-completion.bash文件,点击Raw,然后根据地址栏内容进行下载,存为 ~/.git-completion.bash
curl https://raw.githubusercontent.com/git/git/v2.13.5/contrib/completion/git-completion.bash -o ~/.git-completion.bash
修改 ~/.bash_profile
if [ -f ~/.git-completion.bash ]; then . ~/.git-completion.bash fi
然后执行:
source ~/.bash_profile