[Yanel-dev] showing git branch in command prompt

Michael Wechner michael.wechner at wyona.com
Fri Sep 30 14:28:28 CEST 2011


Hi

A friend of mine pointed out me how to show the git branch in the 
command prompt:

https://duckduckgo.com/?q=show+git+branch+command+prompt

whereas I am currently doing it as follows on a Mac. Add the following 
lines to /Users/MY_NAME/.profile

function parse_git_branch () {
        git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}

RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
NO_COLOUR="\[\033[0m\]"

PS1="$GREEN\u at macbook$NO_COLOUR:\w$YELLOW\$(parse_git_branch)$NO_COLOUR\$ "

and start a new terminal window and then you should see something like:

michaelwechner at macbook:~/src/yanel (master)$

which is more convenient than typing "git branch" ;-)

HTH

Michael



More information about the Yanel-development mailing list