1检查是否安装brew没有安装的请输入以下命令Homebrew官网地址https://brew.sh/index_zh-cnbrew list/usr/bin/ruby -e $(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)2通过brew 安装bash-completionbrew install bash-completion3查看bash-completion 是否安装成功brew list4查看bash-completion 文件信息brew info bash-comletion5根据第四步输出内容的提示把对应的命令行加入~/.bash_profile 文件中## 这里需要注意版本不一样加入的东西不一样具体需要看输出内容的提示## [ -f /usr/local/etc/bash_completion ] . /usr/local/etc/bash_completion这是我操作时输出的内容提示6确认自己电脑已经装git并确定安装的版本brew install gitgit --version7下载git-completion.bash 文件保存至/usr/local 目录## git-completion.bash 可以在GitHub 下载因为这个文件是存放在git 源码中的但是需要注意和本地安装的git 版本一致## https://github.com/git/git/blob/master/contrib/completion/git-completion.bashcurl -L -O https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash8把git-completion.bash 文件复制到用户目录并命名为.git-completion.bashcp /usr/local/git-completion.bash ~/.git-completion.bash9配置~/.bash_profile 文件source ~/.git-completion.bash10保存~/.bash_profile 文件并执行source ~/.bash_profile 命令## 注意我们可以省略第八、九、十步执行以下步骤cd /usr/local/opt/bash-completion/etc/bash_completion.dcp /usr/local/git-completion.bash .brew unlink bash-completionbrew link bash-completion