Git prompt for bash
I don't know who wrote this originally, but this is from my .bashrc. Tridge's is simpler, but has colour!
Before this, I avoided git branches in favour of multiple copies of repositories because I use my prompt to provide location. This provided the missing piece...
# Git me harder! __git_ps1 () { local g="$(git rev-parse --git-dir 2>/dev/null)" if [ -n "$g" ]; then local r local b if [ -d "$g/../.dotest" ] then local b="$(git symbolic-ref HEAD 2>/dev/null)" r="|REBASING" elif [ -d "$g/.dotest-merge" ] then r="|REBASING" b="$(cat $g/.dotest-merge/head-name)" elif [ -f "$g/MERGE_HEAD" ] then r="|MERGING" b="$(git symbolic-ref HEAD 2>/dev/null)" else if [ -f $g/BISECT_LOG ] then r="|BISECTING" fi if ! b="$(git symbolic-ref HEAD 2>/dev/null)" then b="$(cut -c1-7 $g/HEAD)..." fi fi if [ -n "$1" ]; then printf "$1" "${b##refs/heads/}$r" else printf " (%s)" "${b##refs/heads/}$r" fi fi } PS1="${PS1//\\w/\\w\$(__git_ps1)}"