I'm a programmer specialising in performant and scalable systems using PHP and Ruby and cooking


Published:

Git Bash Completion on OSX

Something pretty cool I was told about recently was 2 really handy little scripts that actually ship with the Git source.

Bash Completion

This is pretty cool as this allows you to not only tab out commands in your prompt, but will also complete remote and branch names.

First download and extract the source from the git website.

Then copy the completion file to somewhere, I used "/opt/bash_completion.d" (you may have to create this folder).

cp ~/Downloads/git-1.7.12/contrib/completion/git-completion.bash /opt/bash_completion.d  

Add this to your ~/.bash_profile to enable completion

source /opt/bash_completion.d/git-completion.bash  

(optional) re-source your bash profile so that you get the new changes in your current session

source ~/.bash_profile  

Branch Aware Prompt

Now this is an ulta-cool tool provided with the Git source. This will make your prompt branch aware so when inside a git repository your prompt will detect this and display the branch name in your prompt e.g.:

Harry-Walters-MacBook-Pro:Prospect(master) harry$  

How handy is that? No more forgetting which branch you're in before pushing / pulling. To enable this the steps are pretty simple.

Assuming you still have the git source extracted from step 1 above, copy the prompt script to the same folder as the completion script.

cp ~/Downloads/git-1.7.12/contrib/git-prompt.sh /opt/bash_completion.d  

Add this to the bottom of your ~/.bash_profile to enable the new prompt

source /opt/bash_completion.d/git-prompt.sh  

(optional) As with the above step 4 you may want yo source you bash profile to get the new prompt otherwise just start a new terminal session

source ~/.bash_profile  

Now you're all set for more awesomeness in your Terminal windows!