TL;DR from 2024: Don't do this through the cygwin package manager. Manually install the official git-completion.bash file instead.
Why don't the other answers work for everyone?
"bash-completion" installs the infrastructure needed for bash autocompletion, but if you look at the files it creates, git
is not one of them. Installing it alone will not give you git autocompletion.
"git" installs /usr/share/bash-completion/completions/git
and this gives you git autocompletion, but only when it's loaded. It won't be loaded unless you have "bash-completion" installed, too.
Depending on which of these are already installed, some answers will work for you and others will be incomplete.
What if I don't want to install the cygwin "git" package?
Someone mentioned that they use the Windows git
command, and for that reason, they don't want to install cygwin's git
command. In that case you can skip installing either package and manually install the official git-completion.bash file instead.
If I want the cygwin "git" command?
As mentioned, you can install both packages and probably move on with your life. This probably applies to 99% of the people.
On the other hand, you may not want to use the autocompletion that comes with the "git" package.
To be specific, the autocompletion script won't run until you interact with it first. That matters to me because I need to refer to some of the functions the script creates, and they don't always exist.
Manual install
- Download the file.
- Edit your .bashrc or .bash_profile, etc. to add this line:
source /path/to/git-completion.bash
- If you have installed the cygwin "git" package and want to continue using it,
rm /usr/share/bash-completion/completions/git
so it doesn't interfere with your manual install.