Howto show git branch in bash prompt

This is my normal bash prompt:
The corresponding variable:

PS1='\[\033[0;36m\][\[\e[0;32m\]\u\[\e[0;37m\]@\[\e[0;33m\]\h:\[\e[0;35m\]\w\[\e[0;36m\]]\[\e[0;40m\]\$\[\e[0;37m\] '

To add the git branch, you have to put these lines in your ~/.bashrc:

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

Now it will show the branch in a git directory:

One thought on “Howto show git branch in bash prompt

  1. Pingback: Pimp your prompt | Mein PC spinnt!

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>