Apple - .git-completion.bash producing error on macOS Sierra 10.12.6
I ran into the exact same problem. After some digging, I finally figured out what the root problem is.
They made some major changes to the git-completion.bash
script which requires a new feature in git v2.18, --list-cmds
. The problem is that none of the package managers have updated to git v2.18 yet.
Most of the instructions out there say to download raw.githubusercontent.com/git/git/master
/contrib/completion/git-completion.bash . But that is not necessarily the best option because sometimes you will be downloading a newer git-completion.bash
than your version of git supports.
So the solution is to download the git-completion.bash
version that matches your git version. Then source it again. In this case:
https://raw.githubusercontent.com/git/git/v2.17.1/contrib/completion/git-completion.bash
Notice that it is referencing v2.17.1
instead of master
. Later, when you install git v2.18, then you can switch back to master
, or v2.18
tag.
Upgrading the git to the latest version is the simplest solution. https://git-scm.com/download/mac
After that make sure you follow the steps
curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o ~/.git-completion.bash
Add this small command into the
.bash_profile
fileif [ -f ~/.git-completion.bash ]; then . ~/.git-completion.bash fi
Don't build it from source; instead install from MacPorts.
To install git with auto-completion, issue the following command:
$ sudo port install git +bash_completion
close and reopen your Terminal and git completion should work