479

On my Linux machine I have autocomplete for branches with Git.

[Note we are talking about git branch completion, not bash completion (e.g. commands, files, etc). Thus NOT Lane's answer at all]

For example I can type git checkout+TAB and get a list of branches.

Or I can type git checkout feb*+TAB to get all branches that begin with "feb".

How can I get this functionality on a Mac?

I tried downloading and running bash-completion/bash_completion and bash-completion/bash_completion.sh.in but no joy. The first gave error messages about declare: -A invalid_option. The second gave no errors. When I git checkout+TAB though I am still getting a list of files in the directory, not branches. I am in the project root.

Auto-complete for directories and bash commands are working ok, so it's specific to Git.

  • I just joined this community so I can't yet answer, but I found "oh-my-zsh" to be super super helpful and I really like the UI:
    https://github.com/ohmyzsh/ohmyzsh
    This is, of course, for people using zsh. I'm assuming it doesn't work for bash...
    – Mikael Weiss Jan 30 '21 at 17:07
  • Now that the Mac uses zsh instead of bash this answer may prove useful. – dumbledad Dec 01 '21 at 15:16
  • 2
    for zsh users: echo 'autoload -Uz compinit && compinit' >> ~/.zshrc && . ~/.zshrc link – JillAndMe Oct 14 '22 at 02:58
  • Go to this url https://github.com/git/git/tree/master/contrib/completion
  • Follow the instructions in the completion file that fits your usage, whether its bash or zsh
  • – Michael Guild Jan 09 '23 at 13:44
  • I tired a few answers but none worked, so I tried the suggestion at https://www.macinstruct.com/tutorials/how-to-enable-git-tab-autocomplete-on-your-mac/. Same as JillAndMe's suggestion. Then it worked – Jimmy Long Mar 27 '23 at 01:38