Andrea D. Blog
Andrea, man, html operator, css dispeller, js runner, web lover.

...and definitely It steals the fish.

Improve your GIT prompt

April 9th, 2014

How to get a nice git prompt in no time.

A friend of mine, during a remote shared video session, noticed my shell while we were deciding what to commit and what to merge.

Example of my prompt

Simone told me:

Cool, you should write some instructions on how to configure it...

I want it too!

so here's how to do it

Some time ago I wrote a script for parsing the git status and return numbers of modified files and the current branch. Soon I understood it is annoying to maintain and that there is so much better out there.

use bash-git-prompt

First of all:

$ cd ~ ;
$ git clone .bash-git-prompt ;

Than you have to edit the .bash_profile and add this at the end:

source ~/.bash-git-prompt/

.bash_profile is in your home folder if you are using OSX, otherwise check for a .bashrc if you are using linux or unix.

Doing this you'll have enabled the cool git prompt with its default setting. Setting the GIT_PROMPT_ONLY_IN_REPO variable you are preserving the PS1 when outside a git folder.

customize it

However, the default config probably will hurt you, the default settings is something like this:

Default bash-git-prompt

Don't panic, it's possible to tweak it a bit. Create a file in your home folder called, so:

$ touch

Then you want to write some variables inside it:

Then here's my config for


GIT_PROMPT_PREFIX="${IBlack}(${ResetColor}" # start of the git info string
GIT_PROMPT_SUFFIX="${IBlack})${ResetColor} " # the end of the git info string
GIT_PROMPT_SEPARATOR="${IBlack} ${ResetColor}" # separates each item
GIT_PROMPT_BRANCH="${IBlack}" # the git branch that is active in the current directory
GIT_PROMPT_STAGED="${Green}" # the number of staged files/directories
GIT_PROMPT_CONFLICTS="${Magenta}✖" # the number of files in conflict
GIT_PROMPT_CHANGED="${Yellow}" # the number of changed files
GIT_PROMPT_REMOTE=" " # the remote branch name (if any)
GIT_PROMPT_UNTRACKED="${Cyan}" # the number of untracked files/dirs
GIT_PROMPT_STASHED="${BoldBlue}" #⚑      # the number of stashed files/dir
GIT_PROMPT_CLEAN="${IBlack}✔" # a colored flag indicating a "clean" repository
GIT_PROMPT_START="${ResetColor} "
GIT_PROMPT_END="${ResetColor}${BYellow}\w${ResetColor} ${IBlack}${ResetColor} "

try everything

Logout from the current session and login again, or simply close the terminal and open it again.

Many uses this command source ~/.bash_profile but I do not like it. That way you are not cleaning previous loaded environment variables, so seems better to me perform a clean login.

stay updated

Having this configuration you can keep updated the bash-git-prompt pulling it from github. Periodically give a git pull under ~/.bash-git-prompt

$ cd ~/.bash-git-prompt
$ git pull


That's all. enjoy your cool prompt :D