1.安装git配套脚本完全版
brew install bash-completion
安装完成后会有一段提示:
Add the following lines to your ~/.bash_profile:
if [ -f $(brew --prefix)/etc/bash_completion ]; then
. $(brew --prefix)/etc/bash_completion
fi
2.将if...then之间的语句添加到bash_profile中
3.下载git源码,获取git-completion.bash文件,路径:contrib/completion/git-completion.bash
git clone https://github.com/git/git.git
4.复制到根目录并改名为.git-completion.bash
cp git-completion.bash ~/.git-completion.bash
5.添加下面语句到~/.bash_profile
source ~/.git-completion.bash
重启shell终端,ok!