Quick tip: Adding the current git branch to the shell prompt
January 26, 2010
This information is readily available on the GitHub support pages, but I’m posting it here for reference (do I won’t have to dig it out again the next time I need it).
- Save this file somewhere and source it from your .bashrc or .bash_profile. This provides all sorts of completion magic for git, but I’m not really sure if it’s required for the prompt trick to work🙂
- Update your PS1 to include __git_ps1. Example:
export PS1='[ \u@\h \w$(__git_ps1 " (%s)") ]\$ '
Voila! You now see the current branch when CWD is inside a git repo:
[ jtj@nova ~/projects/eldorado (railsforum) ]$