Notes

Repo for code notes etc.

Show Git Branch via Your Bash Prompt

  • Create the Bash function below to determine what branch you are using:
1
2
3
4
function parse_git_branch {
  ref=$(git symbolic-ref HEAD 2> /dev/null) || return
  echo "("${ref#refs/heads/}")"
}
  • Update your PS1:
1
export PS1="\[\033[01;36m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\\[\033[01;31m\] \$(parse_git_branch)\[\033[00m\]\n\[\033[01;34m\]\$\[\033[00m\] "