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”

Leave a Reply

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