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

RuMAN S
  • 123
  • 7
  • 1
    Do you use vanilla `bash` ? Do you have `zsh` or any completion plugin ? – Aserre Jun 12 '18 at 10:13
  • What you actually need may be modifying the specified auto-complete file. – Geno Chen Jun 12 '18 at 10:38
  • @Aserre I use vanilla ubuntu bash. I will add it to the question for clarification. – RuMAN S Jun 12 '18 at 10:49
  • You should consider using the newer `git switch ` instead of checkout for your navigation between branches. If you accidentally type `git checkout `, you undo all the changes to the file. It's `git switch -c ` to create a new branch and switch to it. – rjmunro Jun 29 '21 at 08:47

2 Answers2

8

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.

FelipeC
  • 9,123
  • 4
  • 44
  • 38
  • Wow, that's a heck of a lot cleaner than deleting stuff out of git-completion.bash. I had no idea this existed. – Ryan Lundy Jun 25 '19 at 15:45
  • 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 Jul 09 '20 at 09:05
  • 1
    @gibatronic Zsh's completion is hopeless. You can use my own completion for Zsh which uses Git's official completion though: https://github.com/felipec/git-completion – FelipeC Oct 05 '20 at 09:34
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.

Ryan Lundy
  • 204,559
  • 37
  • 180
  • 211