2011/09/17

Add Git Branch Name to Bash Prompt

Append following lines to the end of ~/.bashrc

NB: replace '>' with '>'. With syntax highlighting, I can't force it display '>'.

function parse_git_branch {
    ref=$(git symbolic-ref HEAD 2> /dev/null) || return
    echo " ("${ref#refs/heads/}")"
}

PS1="[\u@\h \W\$(parse_git_branch)]\\$ "