user137369 user137369 - 2 months ago 11
Git Question

Homebrew’s `git` not using completion

When using OSX’s git, after I modify a file I can simply do

git commit <tab>
, and that’ll auto complete the file’s name to the one that was modified. However, if I install a newer version of git from homebrew and I use it, that feature no longer works (meaning I press
<tab>
and it just “asks” me what file I want to do it on, even including the ones that have no changes).

Can anyone shed some light as to why, and how to solve that? I’d prefer using homebrew’s git, since it’s more up-to-date.

My shell is zsh, and Neither installing
bash-completion
or
zsh-completions
worked (even after following homebrew’s post-install instructions).

Also, after installing git with homebrew it says

Bash completion has been installed to: /usr/local/etc/bash_completion.d
zsh completion has been installed to: /usr/local/share/zsh/site-functions


So shouldn’t I be able to use one of those?

Answer

You're looking for:

brew install git bash-completion

As warpc's comment states, you'll need to add the following to your ~/.bash_profile to get homebrew's bash-completion working:

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

The above is mentioned in the caveats when you install the bash-completion formula.