Show current git repo in command prompt

Dan showed me at a snippet to slap into your ~/.bash_profile to display the current git branch in your prompt for the working directory (provided it’s a git repo). Very cool stuff.

Here is my version with colours changes to suit my tastes:

function parse_git_branch_and_add_brackets {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\ [\1\]/'
}
export PS1="\[\033[32m\]\u@\h\[\033[00m\]:\[\033[34m\]\w\[\033[36m\]\[\033[0;33m\]\$(parse_git_branch_and_add_brackets)\[\033[00m\]$ "

It looks a little something like this:

Git Branch on Command Line

Leave a Reply