Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save washingtonsoares/fc7365fa32e4fe504f65c66794570ae1 to your computer and use it in GitHub Desktop.
Save washingtonsoares/fc7365fa32e4fe504f65c66794570ae1 to your computer and use it in GitHub Desktop.
List only local branches when autocompleting git checkout (Zsh)
git config --global alias.checkoutr checkout
nano /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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment