Get Git completion to work on Linux and OS X

Published on August 7, 2015 in How-tos
Read time: 1 min
Tags:

Admit it, bash completion is cool and having it also in git is even cooler. But when you install git from source it often doesn’t work. Here’s how to fix it.

In short, you need to have git-completion loaded in your bash. It is best for git-completion.bash to match the version of your installed git.

Download it using the command after changing 0.0.0 with your installed git version.

wget -O ~/.git-completion.bash https://raw.githubusercontent.com/git/git/v0.0.0/contrib/completion/git-completion.bash

Now you need to load it by default in your bash. Add the line below to ~/.bashrc on Linux, to ~/.bash_profile on OS X:

# adding git completion
if [ -f ~/.git-completion.bash ]; then
. ~/.git-completion.bash
fi

Then do:

source ~/.bashrc

if you’re running Linux or

source ~/.bash_profile

if OS X is your OS.

Done!

More

If you want to, you can read more about this in the official git doc.

UPDATE

If it is not working for you, you have to set up bash completion. Check it here.

Thanks for reading.



Comments

Got some words you want to share? Tell me!