I have tried to debug this issue unsuccessfully for several days. I have done my best to install git and git completions on my machine, however I am still unable to autocomplete branch names (local or remote). Completion of git subcommands, however, works just fine.
I have a Mac running Sierra 10.12.5.
$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.12.5
BuildVersion: 16F73
I am using bash, installed via Homebrew.
$ brew info bash | head -1
bash: stable 4.4.12 (bottled), HEAD
I have installed git via Homebrew.
$ brew info git | head -1
git: stable 2.13.1 (bottled), HEAD
I have installed bash-completion via Homebrew.
$ brew info bash-completion | head -1
bash-completion: stable 1.3 (bottled)
I have sourced the necessary script.
$ source $(brew --prefix)/etc/bash_completion
I have confirmed git-completion.bash is in fact in the bash_completion.d directory.
$ ll /usr/local/etc/bash_completion.d/git-completion.bash
lrwxr-xr-x 1 michael 65 Jun 18 02:19 /usr/local/etc/bash_completion.d/git-completion.bash -> ../../Cellar/git/2.13.1/etc/bash_completion.d/git-completion.bash
When using git, I see the correct autocomplete behavior when trying to autocomplete commands.
$ git che{tab}
checkout cherry cherry-pick
However, branch name completions do not seem to work at all. Instead, the autocomplete tries to suggest another subcommand
$ git checkout{tab}
add annotate apply archive bisect [...list continues]
git does know about the other branches of this repository (remote and local).
$ git branch -a
master
* foo
remotes/origin/HEAD -> origin/master
remotes/origin/bar
remotes/origin/foo
remotes/origin/master
However, git will not suggest another branch no matter how many letters I hint.
$ git checkout ma{tab} # => nothing
$ git checkout mas{tab} # => nothing
$ git checkout mast{tab} # => nothing
$ git checkout maste{tab} # => nothing
This is happening within every git repository on my machine, rather than being isolated to one. I have the necessary permissions to read and write to these repositories.
I have tried uninstalling / re-installing git and bash-completion. I have tried grabbing the canonical git-completion.bash script from Github directly and sourcing that instead. I have tried to remove all of my git dotfiles to rule these out.
All the guides I've come across seem to imply that my autocomplete woes will be solved by downloading the latest git-completion.bash (as linked above) and sourcing it, but sadly that isn't cutting it in this case. Bash completions appear to be working normally for other tools (e.g. for tmux), so I believe this issue is localized to the git completions.
Am I missing something? What additional steps do I need to take to activate completions for branch names?
The problem is the version of bash
you're using. Modern bash completion configuration scripts require a newer bash
than Apple ships with macOS. You need to a) install a newer bash
; b) add it to /etc/shells; and c) change your account's shell using chsh
(or System Prefs > Users & Groups > unlock/authenticate > right-click account > Advanced Options).