git config --global alias.checkoutr checkout
$EDITOR /usr/local/share/zsh/site-functions/git-completion.bash
...and then modify the file as follows...
-__gitcomp_nl "$(__git_refs '' $track)"
+if [ "$command" = "checkoutr" ]; then
+ __gitcomp_nl "$(__git_refs '' $track)"
+else
+ __gitcomp_nl "$(__git_heads '' $track)"
+fi
... and source your shell (source ~/.bashrc
/ source ~/.zshrc
...).
Use git checkoutr
for the default behavior and git checkout
(or just gco
) for browsing only local branches. Credits to http://cmetcalfe.ca/blog/git-checkout-autocomplete-local-branches-only.html.
In hopes that it could save another person some time debugging, I just wanted to say I found that I needed to install git from homebrew, and then the autocompletion worked perfectly out of the box with macos Mojave and oh-my-zsh. The system git that comes with developer tools had otherwise worked well for me, I never realized that I was even using it versus git from brew. But for the autocompletion of local branches only to work, I found I needed git from brew.