Just working with a git directory and noticed that whatever trick I was using to get the current git branch visible from my $PS1 variable in bash … stopped working. In discussing if a man page for git(1) was incorrect on #fedora-devel, tmz pointed out to me why it worked that way (short version: refer to the individual git-foo(1) man pages for actual examples, don’t rely upon the git(1) page for how the commands work on the command line.) He also suggested an alternative that is inline with what we do now in git 1.6. Here are the steps I followed.
- Rip out whatever logic you have in ~/.bashrc for displaying the git branch at your command prompt.
- Copy the script supplied by the git package to where you can make it an executable, such as ~/bin :
- cp /etc/bash_completion.d/git ~/bin/git-completion.sh
- Make the script executable :
- chmod 700 ~/bin/git-completion.sh
- Add these two lines to ~/.bashrc :
- source ~/bin/git-completion.sh
- export PS1=”[\u@\h \W"'$(__git_ps1 " (%s)")'"]\$ “
- Reload your bashrc file :
- . ~/bashrc
Enjoy having a peek at where you are in your git directory:
[kwade@calliope lookatgit (debug)]$ git branch * debug help master [kwade@calliope lookatgit (debug)]$