Git's tab autocompletion is useful for small projects, but I'm currently working on two big projects that use git and for these it's worse than useless. Whenever I type, say, git add forms<tab>
, git takes 20 seconds or more to find the file (in this example, forms.py), and in this timespan I can't do anything else in the terminal. Is there any way to turn off the autocompletion feature, or somehow make it faster?

- 30,145
- 48
- 175
- 286

- 2,120
- 4
- 22
- 37
-
Which **shell** are you using? – johnsyweb Mar 21 '12 at 18:09
-
I'm using zsh and I'd like to use zsh's standard filename autocompletion rather than git's. – haroba Mar 21 '12 at 18:14
-
By the way `set -x` is enough to see/prove which autocompletion takes too long. – MarcH Oct 03 '17 at 17:43
-
@Johnsyweb: first line of `git-completion.bash` is: `bash/zsh completion support for core Git` – MarcH Oct 03 '17 at 17:44
6 Answers
It's not git auto completing the file names, it's your shell. Do you have the same delay when doing e.g. "cat forms< tab >"?
Check out this post with similar problems:
http://talkings.org/post/5236392664/zsh-and-slow-git-completion
This post suggests adding the following to your .zshrc:
__git_files () {
_wanted files expl 'local files' _files
}
EDIT: Here's the original text of that post
I found many posts relating complaints about how painfully slow git auto-completion can be in large repositories. There were various suggested patches and suggestions to load the latest zsh. Maybe one of those things would work, but all I really want is for it to complete the names of branches and files as they are in the file system. I did not find any suggestions on how to get this behavior so I figured it out for myself. I thought I would share this for anyone who might benefit from it. I just added the following to my .zshrc file:
__git_files () { _wanted files expl 'local files' _files }
Now I can run git commands and get near instant completion while still getting file completion similar to what ls would provide.

- 16,270
- 4
- 47
- 67

- 127,556
- 20
- 111
- 121
-
If I add a file to .gitignore, tab completion after a git command doesn't work with that file anymore. – haroba Mar 21 '12 at 18:23
-
Ok. Please check my revised answer. It probably has to do with the communication between your shell and git then. – rtn Mar 21 '12 at 18:24
-
Thanks, that worked! I wonder if I should submit a git or zsh bug report, since the solution is very unintuitive. – haroba Mar 21 '12 at 18:28
-
1Your solution worked like a charm, but the link is dead. Could you please explain what this does? Thanks – Mariano May 20 '13 at 23:59
-
1For those asking, it seems that __git_files is the function used for autocompleting git, and this new function scans the filesystem instead of communicating with git. – WouterH Jun 25 '13 at 12:39
-
3This doesn't seem to make a difference for me (I should not my repo consists of a lot of untracked, ignored files, and I'm using Cygwin's ZSH). Obviously something is different on my machine. Any suggestions how I can diagnose the discrepancy? – Sridhar Sarnobat Feb 21 '14 at 19:51
-
Make sure you put this command **before** your zsh plugins, otherwise you might end up with quick autocompletion, but errors once you try to actually run the git command. – Simon Apr 22 '15 at 07:22
Finally fed up with terribly slow auto-completion in zshell and starting looking a solution. I ended up switching from 'git' to using the 'gitfast' plugin that is already installed w/ oh my zsh and am flying... https://github.com/robbyrussell/oh-my-zsh/wiki/Plugins#gitfast

- 4,901
- 4
- 37
- 46
I have no experience with zshell, but I got this answer on another forum. You need to include this line in your .zshrc file:
compdef -d git

- 197
- 4
-
3Unfortunately, this makes completion of git commands fail. For example, if you type `git ch
`, it won't give a list of valid git commands. – amcnabb Mar 21 '12 at 20:07 -
With many git commands the first argument can be either a branch or a filename. Sometimes you want to complete on the filename (which should always be super fast) and then you have to wait a super long time browsing all the branches you didn't care about. Disabling git completion fixes that frequent problem. – MarcH Oct 03 '17 at 17:37
-
1Yes, this turns off autocompletion, which is **exactly** what the OP asked for. – FelipeC Jun 06 '19 at 19:21
-
Thank goodness I found this answer. Hitting
in any repo that had a large LFS files would freeze zsh. Now completion of filenames in commands like 'git diff filename' complete instantly because it is just doing file matching. – user3243135 Sep 10 '20 at 05:18
This is because Zsh comes by default with extremely bloated completion for Git. I wrote a blog post explaining how I fixed this bloatedness, but it had to be outside of the Zsh project.
The easy answer is to install Git's zsh completion, which is different than Zsh's git completion (which comes by default). Download git-completion.zsh, and place it in your ~/.zsh/_git
. Then place it on your fpath:
fpath=(~/.zsh $fpath)
You should be flying now.
As another comment here explains; another option is to use oh-my-sh and enable the gitfast plugin, which achieves the same thing.
Why would Zsh developers insist on making their code slow? I don't know, but here you can see a sample of their reasoning: Re: Slowness issue with git completion.

- 9,123
- 4
- 44
- 38
One very quick and dirty solution is to delete the following file responsible for the auto-completion.
/usr/local/git/contrib/completion/git-completion.bash
-
1I can't do that since I'm not the only user on this server, and others may or may not want to use git autocompletion. It seems odd that git would not have an easy fix for something which, unless I'm misunderstanding something, happens to all git projects when they get large. – haroba Mar 21 '12 at 18:19
-
2
-
2
-
1Besides that doesn't matter: that's for Bash, his problem is with Zsh. By default Zsh loads its bloated completion stuff. – FelipeC Jun 06 '19 at 19:18
According to the answer to git bash auto complete slow on windows 7 x64, git 2.13 comes with a faster git-completion.bash

- 18,738
- 1
- 30
- 25
-
1
-
@FelipeC, your own blog explains that it's possible (not saying "recommended") to use git-completion.bash in zsh. – MarcH Jun 06 '19 at 22:12
-
-
You commented and voted down without even pointing at your own explanation. Weird. – MarcH Jun 06 '19 at 22:52
-
This is what happens when you source that file in zsh: "WARNING: this script is deprecated, please see git-completion.zsh". I wrote that warning for a reason, and Git developers agreed; you need to use the new method. Yes, you **can** still do it, but it's not recommended, it has been deprecated for years, and we should probably remove it already. – FelipeC Jun 07 '19 at 14:08