Reputation: 63
How to enable auto-completion with Git?
When using Git on different platforms, auto-completion is not always enabled/available.
Note that this question is NOT a duplicate of git auto-complete for branches on the command line, because that question was only about Apple users. This question is mostly the same, but including other platforms too.
Upvotes: 4
Views: 8885
Reputation: 2756
You need to get bash
's programmable completion configured to return the possible commands. You can see the "Programmable Completion" section in the bash
man page if you want to implement it yourself.
A much easier method to use a script to pre-configure bash's programmable completion. On most distributions, the file for git completion, /etc/bash_completion.d/git
(on Fedora and derivatives), /usr/share/bash-completion/completions/git
(on Debian and derivatives) (other distributions might have it in other places, try locate
or find
to locate it) are provided by the git
package. (If it is not included with your git package, you can get it from here).
You can configure bash
to source the file when it is started (probably using .bashrc
), or you can install bash-completion
, which will automatically load completions like the one that the git
package installs (and generally completions from /etc/bash_completion.d/
or /usr/local/etc/bash_completion.d/
(typically BSDs)). On most distributions, bash-completion
should be available in the repositories and you can simply install the package. For other systems, see the instructions included in the README.md
to install it. (On non-GNU/Linux systems, some completions might need to be disabled to prevent it from outputting errors when starting)
Upvotes: 4
Reputation: 63
See question git auto-complete in the command line
Solution tested with Debian 9 (Stretch)
sudo apt install bash-completion
Pros:
sudo apt update
then sudo apt upgrade
I also know that the question was asked for Apple users, but it shows up first in Google for "git auto-completion branch", so I thought a Linux answer would still be useful.
Upvotes: 2