根据个人实践,本功能的实现要求 git 是通过 Homebrew 安装的。其他方式安装的不起作用,具体原因不详。

安装 bash-completion

使用 Homebrew 安装

  1. brew install bash-completion

修改 ~/.bash_profile

~/.bash_profile 中添加下方代码:

  1. if [ -f $(brew --prefix)/etc/bash_completion ]; then
  2. . $(brew --prefix)/etc/bash_completion
  3. fi