Add Git branch information to bash prompt
Add the follow to your ~/.bash_profile to display the current directory's Git branch in the bash prompt:
export PS1="\[\033[0;37m\] \w \[\033[31m\]\`ruby -e \"print (%x{git branch 2> /dev/null}.each_line.grep(/^\*/).first || '').gsub(/^\* (.+)$/, '(\1) ')\"\`\[\033[37m\]$\[\033[00m\] "
Written by Matt Hodges
Related protips
3 Responses
If' you are using linux you can simply simply add the __git_ps1
variable.
GIT_PS1_SHOWDIRTYSTATE=true
GIT_PS1_SHOWUNTRACKEDFILES=true
GIT_PS1_SHOWUPSTREAM="verbose"
export PS1="\t]\[\e[${ps_color}m\]\h:\w\[\e[0m\] \$(__git_ps1 '(%s)')>
Will produce something like this:
12:55:52]machineName:/home/user/dir (branchname *% u=)>
Where *
means modified files exist -- from SHOWDIRTYSTATE
%
means untracked files -- from SHOWUNTRACKEDFILES
u=/+/-
means same/ahead/behind remote -- from SHOWUPSTREAM
There's also scm_breeze, which adds awesome shortcut commands, pretty output and some keyboard shortcuts. Currently supports {bash, zsh} and {git}.
+1 for what brombomb said. Only newer git versions require to 'source' the git-prompt.sh shipped with the git distribution (or source your own).