Show the current git branch on the shell prompt

5) Show the current git branch on the shell prompt

Add this to your ~/.bash_profile script

parse_git_branch() {
     git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\u@\h \[\033[32m\]\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\] $ "

Now when your working at your shell prompt, you will see the name of the current working git branch in parens. Here, the shell prompt is telling me that my CWD (current working directory) is ~/Work/_LEARNING/rails-6-0-test and that the branch I’m on is master.