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
blog comments powered by Disqus