6

With new versions of git new commands have been added which I will probably never use.
Is there a way I can disable these commands so that I my tab completion is faster?
For ex: before, git check<tab> would autocomplete to git checkout
But now git check<tab> doesn't tab complete due to there being git check-mailmap in the newer git version.

This is just one of the example.

Alternatively it would be great if I could "force" git to tab-complete "check" to checkout .

Edit: I use vanilla bash with no extra modifications

4
  • 1
    Do you use vanilla bash ? Do you have zsh or any completion plugin ? Commented Jun 12, 2018 at 10:13
  • What you actually need may be modifying the specified auto-complete file. Commented Jun 12, 2018 at 10:38
  • @Aserre I use vanilla ubuntu bash. I will add it to the question for clarification. Commented Jun 12, 2018 at 10:49
  • 1
    You should consider using the newer git switch <branch> instead of checkout for your navigation between branches. If you accidentally type git checkout <filename>, you undo all the changes to the file. It's git switch -c <branch> to create a new branch and switch to it. Commented Jun 29, 2021 at 8:47

3 Answers 3

9

The official way is to use the configuration completion.commands and remove the ones you don't want:

git config --global completion.commands -check-mailmap 

However, you can do even more. There is a hack in __git_main() used for testing that you can abuse to do what you want:

GIT_TESTING_PORCELAIN_COMMAND_LIST="$(git --list-cmds=list-mainporcelain,alias)" 

This will force Git's completion to show only the main commands (and aliases).

You need Git v2.18 or newer for these to work.

Sign up to request clarification or add additional context in comments.

3 Comments

Wow, that's a heck of a lot cleaner than deleting stuff out of git-completion.bash. I had no idea this existed.
Couldn't make it work on zsh… am I doomed? It's impossible to search about it, all results are generic auto-complete setup guides.
@gibatronic Zsh's completion is hopeless. You can use my own completion for Zsh which uses Git's official completion though: github.com/felipec/git-completion
3

To see how to remove items from the autocomplete, see FelipeC's answer.

An alternative is to use git aliases to create shorter alternatives to the commands you commonly use. For example:

git config --global alias.co checkout

Now you can type git co to check out files.

4 Comments

I didn't know we could set aliases! This is much better than what I wanted originally. Thank you!
The _git_foo() functions only get called after the user has typed 'git foo <tab>`.
@FelipeC Feel free to post a better answer about how to remove commands from Git's autocomplete. That would help everyone.
@RyanLundy I was typing exactly that.
1

For zsh, I found this worked well for me too:

zstyle ':completion:*:*:git:*' ignored-patterns 'commit-graph' 'commit-tree' 'check-attr' 'check-ignore' 'check-mailmap' 'checkout-index' 'check-ref-format' 'cherry' 'diff-files' 'diff-index' 'difftool' 'diff-tree' 

Add the above in ~/.zshrc and source it, hope this helps future visitors

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.