Cygwin git tab completion

16.1k views Asked by At

I installed Cygwin on windows and one of the default packages is git tab completion, but I don't have tab completion.

I did some searching and found a note saying it isn't enabled by default. I copied the skel .bashrc and .bash_profile to ~ and in .bashrc I uncommented the lines for completion and then relaunched the console. Still nothing.

I then noticed that the file .bash_completion was not present in /etc, so I found a copy of that online and put it in place, but I still have no completion in git.

It seems there should also be a /etc/bash_completion.d directory with git/ in it, but I don't have that either.

8

There are 8 answers

6
sesm On

Updated for 2016: Install package bash-completion.

3
AudioBubble On

In my .bashrc

 for file in /etc/bash_completion.d/* ; do
    source "$file"
 done
1
vito On

I stumbled on the same issue few days ago and installing bash-completion was not enough.

The issue was solved in my case downloading https://github.com/git/git/blob/master/contrib/completion/git-completion.bash and copying it into /etc/bash_completion.d/

See also: https://git-scm.com/book/en/v1/Git-Basics-Tips-and-Tricks

1
Johann On

The answer above prints out bash: have: command not found for nearly every script in bash_completion.d/. This answer from the linked post solves it for me:

if [ -f /etc/bash_completion ]; then . /etc/bash_completion fi

The script/program /etc/bash_completion already includes the scripts in /etc/bash_completion.d and also defines some functions needed by the included scripts.

However, beware that this will slow down the loading of your shell, especially in Cygwin (slowed to about 1 second load for me). To mitigate this, you can rename everything in /etc/bash_completion.d/ to *.bak, and then remove the .bak selectively from the commands you actually care about (thanks to Slow load time of bash in cygwin).

Update: The file /etc/bash_completion magically disappeared (looks like it was due to upgrading the bash-completion package to 2.1-1). As a quick solution, I just created a symlink in /etc to /usr/share/bash-completion/bash_completion.

Update 2: Re-reading the original question, the issue with not having an /etc/bash_completion.d directory might be related to not installing the "bash-completion" package in Cygwin.

2
bblues On

As of May 2016, I was able to get git & svn tab completion working by simply installing the bash-completion package using the Cygwin setup utility (v2.874) found here: https://www.cygwin.com/install.html. Make sure to select the 'Install from Internet' option. The bash-completion package is listed under the Shells category.

0
superbadcodemonkey On

You can also source git-completion.bash directly from your Git Bash installation in .bashrc:

source /cygdrive/c/Program\ Files/Git/mingw64/share/git/completion/git-completion.bash

This works for git-prompt.sh as well.

This avoids having to install git through Cygwin separately, which could potentially be a different version than your Windows installation. Counterintuitively, the bash-completion package is not required.

0
Alfredo Carrillo On

I had to install the following Cygwin packages:

  • bash-completion
  • bash-completion-devel
0
Evmorov On

To install "git-completion" package run from cmd.exe:

cyg-get git-completion

You don't need to modify your .bashrc after that.