How can I set up autocompletion for Git commands?

You need to install this package if missing. And then logout and login.

apt-get install bash-completion

Put the following lines in your ~/.bashrc

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.


The shortest way to activate the bash auto-completion for Git on Debian is to add

source /etc/bash_completion.d/git

to the ~/.bashrc (and restart the terminal).

See also here: "Pro Git" -> 2.7 Git Basics - Tips and Tricks -> Auto-Completion.


You need to source /etc/bash_completion.d/git to enable git auto-completion.

In my .bashrc it's done with:

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