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)]$
When I pointed tmz at the post, he had one more comment:
You know you want to try out this:
export GIT_PS1_SHOWDIRTYSTATE=true
export GIT_PS1_SHOWUNTRACKEDFILES=true
PS1='[\u@\h \W]$(__git_ps1 ” (%s)”)\\$ ‘
This will show you that there are uncommitted/untracked files as well as the current branch 🙂
I had blogged about it earlier:
http://blog.fedora-fr.org/bochecha/post/2009/08/A-git-aware-prompt-(part2)
Great! Thanks for the additional tips.
I wonder sometimes why we don’t do these sorts of tips and tricks on the Fedora wiki. It’s not much harder to do. Maybe we don’t yet think of it as an end-user wiki with useful how-to content?
I wonder this even while I perpetuate the problem …
> « I wonder sometimes why we don’t do these sorts of tips and tricks on the Fedora wiki. »
Fixed 🙂