Bash Snippet for Git Users

Keeping track of what branch you are using while in a git repository can be a bit of a pain. Adding the following code to your ~/.bashrc file can make it a bit easier since it will prepend your prompt with the current branch.

function parse_git_branch {
    GIT_BRANCH=$(git branch --no-color 2> /dev/null | awk '{if ($1 == "*") { printf "(%s) ",$2}}')
    PS1="$GIT_BRANCH\[email protected]\h:\w\$ "

Here it is working:
[email protected]:~$ source /etc/bash.bashrc 
[email protected]:~$ cd programming/bits
(master) [email protected]:~/programming/bits$