Git自动补全配置安装(Mac版本)

首先要安装 bash-completion,看一下自己的bash命令是否可以补全,如果不行要先安装bash-completion

brew install bash-completion
下载git源码
使用如下命令即可下载

git clone https://github.com/git/git
复制 git-completion.bash
源代码下有个 contrib/completion 目录,有个 git-completion.bash 文件

cd git/contrib/completion/
将该文件复制到主目录(~)下。注意:复制时,文件名前加一个"点"(.),命令如下:
cp git-completion.bash ~/.git-completion.bash
修改主目录下的 .bashrc 文件(如果没有该文件,新建一个)。添加一行代码
source ~/.git-completion.bash
 

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

# git auto completition
if [ -f ~/.git-completion.bash ]; then
. ~/.git-completion.bash
fi
然后,source一下使其生效

source ~/.git-completion.bash
source ~/.bash_profile
这样就可以,按下Tab键就可以提示啦。(如果还不可以,重启终端试试)

$ git che
checkout cherry cherry-pick

切换mac shell:

https://support.apple.com/zh-cn/HT208050

原文地址:https://www.cnblogs.com/sameen/p/14860717.html