Show git branch in shell prompt

nano ~/.bashrc
Paste in:

function parse_git_branch_and_add_brackets {
  git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\ \[\1\]/'
}
PS1="\h:\W \u\[\033[0;32m\]\$(parse_git_branch_and_add_brackets) \[\033[0m\]\$ "

Save. You will probably need to log out and back in to see this.

Leave a Reply

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