Git auto-completion not working on Mac OSX 10.11.5 El Capitan
Solution 1:
You are confusing the basic bash completion with the add on required for completing git commands.
The git
that is installed by Apple lacks the required git-completion.bash
file so you need to install the full git. You can do this easily with homebrew -brew install git
will do the job.
Once you've done that then uncomment your top three lines :-
if [ -f $(brew --prefix)/etc/bash_completion ]; then
. $(brew --prefix)/etc/bash_completion
fi
Now source ~/.bash_profile
and it should work fine.
Solution 2:
As a note for users, like me, who already updated to macOS Catalina, which deprecated bash
, yet ended up at this answer as a top result...
For macOS Catalina+, which uses zsh
, there are a few other requirements. Download both scripts:
curl -o git-completion.bash https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash
curl -o _git https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.zsh
Then update your ~/.zshrc
with:
zstyle ':completion:*:*:git:*' script ~/.zsh/git-completion.bash
fpath=(~/.zsh $fpath)
autoload -Uz compinit && compinit
Solution 3:
With the help of this answer I solved it using these commands
curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o ~/.git-completion.bash
Then I edited the file by running vi ~/.zshrc
and added following part to it
if [ -f ~/.git-completion.bash ]; then
. ~/.git-completion.bash
fi
Then I did run source ~/.zshrc
then git suggestions started working properly.