Git Status in Command Line
There are many tricks out there to get the git status to show in the command line path, but here’s one that worked the best for me on a Mac OS X Snow Leopard machine.
Download the git tarball, and find the contrib/completion/git-completion.bash file. Move it to a good location on your system. In my situation I went with:
/opt/local/etc/bash_completion.d/git-completion
Import that code into your .bash_profile and then add in the code necessary to append the branch name output:
. /opt/local/etc/bash_completion.d/git-completion
PS1='\h:\W$(__git_ps1 "(%s)") \u\$ '
You’re done. If you’re getting the “command not found” error after restarting the terminal, be sure your completion file is in the right spot.
If you want to color things a bit, you could change it to one of the options below:
RED="\[\033[0;31m\]"
GREEN="\[\033[0;32m\]"
YELLOW="\[\033[0;33m\]"
BLUE="\[\033[0;34m\]"
PURPLE="\[\033[0;35m\]"
TEAL="\[\033[0;36m\]"
GRAY="\[\033[0;37m\]"
WHITE="\[\033[0;38m\]"
PS1="$TEAL\h: $GRAY\W$GREEN \$(__git_ps1 '(%s)')$WHITE \$ "
A ton of different ways can be found here:
http://asemanfar.com/Current-Git-Branch-in-Bash-Prompt