working How to configure git bash command line completion?
install bash completion (8)
E.g. on a fresh ubuntu machine, I've just run
sudo apt-get git, and there's no completion when typing e.g.
I didn't find anything on http://git-scm.com/docs, but IIRC completion is included in the git package these days and I just need the right entry in my bashrc.
Most of the instructions you see will tell you to download
and source that in your bash startup script like
But there is a problem with that, because it is referencing the
master branch, which is the latest version of
git-completion.bash. The problem is that sometimes it will break because it is not compatible with the version of git you've installed.
In fact, right now that will break because the
git-completion.bash has new features that requires git v2.18, which none of the package managers and installers have updated to yet. You'll get an error
unknown option: --list-cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config
So the safest solution is to reference the version/tag that matches the git you've installed. For example:
Note that it has a
v2.17. in the URL instead of
master. And then, of course, make sure to source that in the bash startup script.
sudo apt-get install -y git-core bash-completion
For current session usage
To have it always on for all sessions
echo "source /usr/share/bash-completion/completions/git" >> ~/.bashrc
on my ubuntu there is a file installed here:
you can follow the links into the
/usr/lib/git-core folder. You can find there an instruction, how to set up PS1 or use
On Github in the Git project, They provide a bash file to autocomplete git commands.
You should download it to home directory and you should force bash to run it. It is simply two steps and perfectly explained(step by step) in the following blog post.
I have tested it on mac, it should work on other systems too. You can apply same approach to other operating systems.
on most distributions, git completion script is installed into
/usr/share/bash-completion/completions/git) when you install git, no need to go to github. You just need to use it - add this line to your
source /etc/bash_completion.d/git # or source /usr/share/bash-completion/completions/git
In some versions of Ubuntu, git autocomplete may be broken by default, reinstalling by running this command should fix it:
sudo apt-get install git-core bash-completion
You can install git completion using Homebrew or MacPorts.
$BASH_VERSION > 4:
brew install [email protected] (updated version)
Pay special care which version of bash you have as MacOS default ships with 3.2.57(1)-release.
if [ -f /usr/local/share/bash-completion/bash_completion ]; then . /usr/local/share/bash-completion/bash_completion fi
For older versions of bash:
brew install bash-completion
[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion
sudo port install git +bash_completion
then add this to your
if [ -f /usr/share/bash-completion/bash_completion ]; then . /usr/share/bash-completion/bash_completion fi
more info in this guide: Install Bash git completion
Note that in all cases you need to create a new shell (open a new terminal tab/window) for changes to take effect.
There is a beautiful answer here. Worked for me on Ubuntu 16.04
Git Bash is the tool to allow auto-completion. Not sure if this is a part of standard distribution so you can find this link also useful. By the way, Git Bash allows to use Linux shell commands to work on windows, which is a great thing for people, who have experience in GNU/Linux environment.
You just need to source the completion script
i had same issue, followed below steps:
curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o ~/.git-completion.bash
then add the following lines to your
.bash_profile (generally under your home folder)
if [ -f ~/.git-completion.bash ]; then . ~/.git-completion.bash fi