- 下载git-completion.bash 并放到home 目录下:
curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o ~/.git-completion.bash
- 将如下行放到
.bash_profile
文件中
if [ -f ~/.git-completion.bash ]; then
. ~/.git-completion.bash
fi
将其立即生效:
source ~/.bash_profile
此时就可以代码补全了,比如我要切换到某个branch,则只需要输入git branch 然后按「TAB」键即可选则需要的branch分支了。