Including the git branch in the bash prompt

Put the following in ~/.bashrc to add the current git branch on the commandline prompt:

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

PS1='\[\033[01;32m\]\h\[\033[00m\]:\[\033[01;34m\]\W\[\033[00m\]\[\033[01;32m\]$(parse_git_branch)\[\033[00m\]\$ '

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License