For this to work you need to source git's autocompletion which can be found in the contrib/completion-folder of the source distribution. After you've sourced it (through your .bashrc, .bash_profile, ...) you get some additional functions and esp. __git_ps1 which gives you the current branch name in nice brackets. If you take a look into the git-completion.bash file, also look at this paragraph:
# 4) Consider changing your PS1 to also show the current branch: # PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ ' # # The argument to __git_ps1 will be displayed only if you # are currently in a git repository. The %s token will be # the name of the current branch.
So add $(__git_ps1 " (%s)") to your PS1 and you should all be set. It's also sweet in this regard, that it also works when you're some folders within a git repository. Thanks Martin for this trick :D
Have a look at my setup: http://gist.github.com/31934
It not only tells you the branch but also if there are changes to commit and if your current branch is fallen behind or is ahead of the remote branch.
Looks something like this: screenshot
Greetings
Dec. 5, 2008, 9:42 a.m.