Wednesday, October 17, 2012

How to configure Mac OS X terminal to support git completion and context based prompt?

Msysgit on Windows has several nice features:
  • git commands completion upon press <tab>
  • current git branch name in terminal command prompt
By default git on Mac OS X doesn't have these nice features. Let's configure OS X terminal to support them:
  1. Download two scripts (in $HOME/bin folder) from git contrib which support these features (
    cd ~
    mkdir bin
  3. Now we should update .bash_profile file:
  4. export PATH="$HOME/bin:$PATH"
    source ~/bin/git-completion.bash
    source ~/bin/
    export PS1='[\w$(__git_ps1 " (%s)")]\n\$ '
So, here we have:
  • git-completion.bash does all <tab> completion "magic"
  • is responsible for adding git current branch info, see __git_ps1 function call when defining PS1 variable