Introduction
Adding git completion to the git command line can be super handy. Especially when it comes to branch names and other things which can be lengthy. Not to mention, it just means you’ll have less to type which is always good for efficiency. Getting this to work may not be straight forward for everyone, but is pretty easy to do in Arch Linux and here’s how it’s done.
1. Locate Git Completion
First thing we need to do is find out where the bash completion script is, if it even exists on your machine. Please take note of where your git-completion.bash
file resides and use that location for the following steps.
sudo find / -iname “git-completion.bash”
/usr/share/git/completion/git-completion.bash
If for some reason you don’t have the git-completion.bash
script available on your machine, don’t worry, we can pull it down manually by issuing the following command.
sudo curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o /usr/share/git/completion/git-completion.bash
This will simply pull the online git-completion.bash
script into your /usr/share/git/completion
directory. Feel free to put this wherever you want, just note and replace the path in the next steps.
2. Local Link
This next step makes life a little bit easier, it’s not absolutely necessary but it’s a good habit to get into on a per user basis. Let’s create a symbolic link from our local home directory to the shared git-completion.bash
file.
ln -s /usr/share/git/completion/git-completion.bash .git-completion.bash
3. Adding Git Completion
Now that we have everything where we want it, we can update our local ~/.bashrc
to include it. Open your ~/.bashrc
in your editor of choice and add the following.
# Add git completion
if [ ~/.git-completion.bash ]; then
. ~/.git-completion.bash
fi
4. Source Your File
Lastly, let’s source our ~/.bashrc
to get everything in play and start testing it out.
source ~/.bashrc
With that, we can now try out a few commands and hit tab to see branch names and other such items complete.
Conclusion
That’s all there is to it. I hope this helped you get your git completion setup and makes life just a little easier. As always, please let me know if you have any issues and thanks for stopping by.
0 Comments