My custom git prompt on Mac OS X – v1


This post is mainly a reminder for future me when I’ll make this configuration again, or share it with other people. I followed those two resources from Christophe Porteneuve, that I recommend you to read if you’re into git :

Why a custom git prompt ?

It’s been a few months since I’ve been using this custom git prompt and I would not leave it for anything :

  • It saves me time
  • It saves me mistakes
  • I get instant access to infos such as :
    • active branch
    • status (untracked files remaining / modified files / stashed files …)
  • git commands completion


This is about my own current git prompt config on Mac OS X, please take a look at the links I put on the credits section, so that you could have it your own way and make your very own git config.

Configuration on Mac OS X

This post is only about Mac OS X, we’ll need to upgrade the git version shipped with the OS (git 1.9.3 on Yosemite) to the latest stable one : (currently git 2.2.1), to do that, I’ll use Homebrew (feel free to use your own package manager or any other means).

Upgrade git :

$ brew update
$ brew install git

Check the git version in an other prompt : git --version
If not correct (if brew doctor is ok, you shouldn’t have to), run the following command (you may be using an other file than ~/.bash_profile, according to your shell) :

$ echo 'export PATH="/usr/local/bin:/usr/local/sbin:~/bin:$PATH"' >> ~/.bash_profile

Install bash-completion :

$ brew install bash-completion

nano ~/.bash_profile , add the following inside the file :

if [ -f $(brew --prefix)/etc/bash_completion ]; then
 . $(brew --prefix)/etc/bash_completion
#export PS1='\u@\h:\w$(__git_ps1) \$ '
export PROMPT_COMMAND='__git_ps1 "\u@\h:\w" " \\\$ "'

For better logs : nano ~/.gitconfig (it may already exist, if not create it) and add the following (source) :

 st = status
 ci = commit
 lg = log --graph --pretty=tformat:'%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%an %ar)%Creset'
 oops = commit --amend --no-edit

Go to a local git repo and see the magic of your new git prompt !

Other resources :

Update : My gitconfig and some more infos (like how to setup a visual diff/merge tool)

Leave a Reply

Your email address will not be published. Required fields are marked *