Simple Git Trick for Bash

Chris Cormack shared this useful trick for keeping track of what git repo you are currently using/editing. Stick it in your .bash_profile to have your prompt adapt to the repo you are in!

function parse_git_branch {
  ref=$(git-symbolic-ref HEAD 2> /dev/null) || return
  echo "("${ref#refs/heads/}")"
}
RED    ="\[\033[0;31m\]"
YELLOW ="\[\033[0;33m\]"
GREEN  ="\[\033[0;32m\]"
PS1="$RED\$(date +%H:%M) \w$YELLOW \$(parse_git_branch)$GREEN\$ "

Tags: , ,

4 Responses to “Simple Git Trick for Bash”

  1. Chris Says:

    The colours of course are optional :) The green makes me feel like im back in 1985 :)

  2. john.beppu Says:

    I didn’t even have a computer in 1985.

  3. Chris Says:

    Hmm in 1985 it would have been an apple IIe. Having just sold my zx spectrum

  4. Owen Says:

    Cool trick, although it didn’t show up until I’d logged out and logged back in. I think I’ll tweak the colors: 1985 was amber for me, not green ;)

Leave a Reply