Hacker Notes: Git Branch in Shell Prompt

Hacker Notes: Git Branch in Shell Prompt

2011, Sep 02    

Add this to the bottom of your .bash_profile or .bashrc

#Add git info to prompt (attaching to working directory)
function git_branch {
git branch --no-color 2> /dev/null | \
sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
YELLOW="\[\033[0;33m\]"
LIGHT_GRAY="\[\033[0;37m\]"
PS1="$LIGHT_GRAY\h:\W $YELLOW\$(git_branch) $LIGHT_GRAY\u\$ "