Git-completion.bash Mac Download

I just made it work! First install with brew bash-completion just running brew install bash-completion. Then download this two files git-completion.bash git-flow-completion.bash. Nov 25, 2017.

Contents:

This is a re-blog of How To Enable Git Tab Completion In Bash On Mac OS X.

Original post: contents

By Conor Livingston:

I use git from the command line all day long. In the process, I issue a lot of git commands. This can get (no pun intended) to be a lot of repetitive typing, especially when branch names get long. To illustrate, it’s no fun to type out git checkout feature/shiny-new-processing-system-database-optimization every time I want to checkout that branch. Of course, you can always use the mouse to copy and paste a long branch name rather than typing the whole thing out.

Download

However, if you’re like me and like to keep your hands on the keyboard, this solution can feel slow. Tab completion would certainly be faster and easier. Unfortunately, the default install of git on some Mac computers doesn’t have tab completion enabled. This was the case for me and at least two of my colleagues.

Fortunately, this is an easy fix. There is a bash script that enables tab completion of git commands and branch names. At the time of writing, this file exists in git’s official repo on Github. In fact, it is likely that this file already exists on your local machine, but, if you’re reading this post, you probably haven’t tapped into its power, yet. In the rest of this article, I will show you how to enable git tab completion in bash on a Mac.

The first step is to figure out whether you already have the git-completion script on your machine. You can use the command sudo find / -type f -name “git-completion.bash” to see if the script already exists on your local machine. Note: the sudo command will require you to enter the password you use to log in to your Mac. Also, this command may take a minute to run, because it looks through your whole file system. Here are some possible locations for the git-completion script, but it’s okay if it’s somewhere else.

/Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-completion.bash
/Library/Developer/CommandLineTools/usr/share/git-core/git-completion.bash
/usr/local/Cellar/git/2.3.0/etc/bash_completion.d/git-completion.bash
/usr/local/Cellar/git/2.3.0/share/zsh/site-functions/git-completion.bash
/usr/local/etc/bash_completion.d/git-completion.bash
/usr/local/share/zsh/site-functions/git-completion.bash

Mac Git Completion


If the git-completion.bash script doesn’t exist on your machine, please retrieve it from the link I provided above and save it to your local machine in a new file called git-completion.bash in the /usr/local/etc/bash_completion.d/ directory.

If the git-completion.bash script exists on your machine, but is not in the /usr/local/etc/bash_completion.d/ directory, we should create a copy of it in that directory. A quick sudo cp /current/path/to/your/git-completion.bash /usr/local/etc/bash_completion.d/git-completion.bash should do the trick.

For those who are curious about the /usr/local/etc/bash_completion.d/ directory: it’s for storing new completion commands, and you may have to create it if it doesn’t already exist on your machine.

At this point the git-completion.bash script should exist on your local machine in the /usr/local/etc/bash_completion.d/ directory.

Now we’ll plug the git completion script into bash by pointing to it from ~/.bash_profile. Note: the tilde in the previous sentence refers to the home directory on your computer. Add the following line to ~/.bash_profile: source /usr/local/etc/bash_completion.d/git-completion.bash and save.

The final step is to reload your bash profile. You can achieve this by running source ~/.bash_profile in your current bash session.

There you have it! You should now be able to use tab completion with git commands and branch names. Try it out by typing “git chec” into your terminal and pressing tab. The git-completion script should snap into action and complete your command, so that it reads “git checkout.”

Additional notes: contents

Git Bash Download Mac

Creating a symbolic link instead of copying the file should be enough:

On my system, it was like this:

If you want to make the changes system-wide instead of for just the current user, rather than add the source line to ~/.bash_profile you can add it to /etc/bashrc.

WARNING: Before making changes to /etc/bashrc, it is recommended to make a backup of the original:

This is my entire /etc/bashrc file:

When working in GIT based software projects that have a broad range of GIT branches the need for autocompletion of these branch names and GIT commands in general in the shell is one of the first tasks you want to setup for your developers (and yourself ;). After all it’s all about removing impediments to get highly motivated developers who produce high quality code in return, isn’t it?

Setup git-completion.bash in your shell to enable command and branch name autocompletion

By default GIT ships a file called git-completion.bash (at least on Linux, Mac and most probably other major platforms as well) that when setup in your shell will autocomplete commands and branch names, nice right! This file actually represent a comprehensive ruleset that will autocomplete all kinds of GIT commands, try it out you will be amazed.

Normally you find this file in contrib/complete/git-completion.bash but you can also download it from github.

All you have to do to enable branch name and command autocompletion for GIT is to add a source reference to git-completion.bash in your shell’s profile (~/.bashrc or ~/.profile). So open up your shell’s profile (I’ve chosen ~/.profile here)

and add a source call to the git-completion.bash file

In case there’s no immediate effect do a manual source call on your shell profile file:

$ source ~/.profile

This should be all to enable branch name autocompletion for GIT. Enjoy your developers’ and your new productivity!