How do you use an existing completion for a function in zsh?

If I write a zsh function like this

function git_checkout_with_selecta() {
  if [[ -z $1 ]]; then
    git checkout `git branch --no-merged | selecta`
    git checkout "$@"
alias gco='git_checkout_with_selecta'

How can I apply the same tab completions that I have for ‘git checkout’ to the alias for the function ‘gco’?

  • What does git log --all do?
  • What are valid use cases for -m2 in git revert for a merge commit?
  • Git branch labels with symbols appearing on my command line
  • How do I prevent some branches from ever being fetched by others?
  • Formatting Git Log for HTML
  • Git: Object in Version Control cannot be removed
  • How do I use Github to access the same project files from different computers?
  • Techniques for selectively submitting to a main repo
  • How to open Git Bash from Git Gui?
  • Global Xcode run scripts
  • Ignoring certain files and changes in capistrano's current directory for development environment
  • git pull error for git update-index --assume-unchanged files
  • 2 Solutions collect form web for “How do you use an existing completion for a function in zsh?”

    compdef _git gco=git-checkout

    This will use the _git completion function, and sets git-checkout as the service/sub-command.

    Something like:

    compdef gco=git 

    If your completer triggers on git.

    Git Baby is a git and github fan, let's start git clone.