22 May 2010 - San Antonio
I like knowing which Git branch I’m currently in. I use the git-ps1 function feature that comes with git-core. If you clone or download the git source:
git clone git://git.kernel.org/pub/scm/git/git.git
There is a file in the contrib/completion folder called git-completion.bash:
~> cd git/contrib/completion
total 96 -rwxr-xr-x 1 user staff 44K Apr 14 15:26 git-completion.bash
I copy this file to my $HOME folder as .git-completion.bash and then reference it and the ps1 prompt feature in my .bashrc file
~> cp git-completion.bash ~/.git-completion.bash
inside by ~/.bashrc file
export PS1='\w$(__git_ps1 "(%s)") > ' source ~/.git-completion.bash
And now whenever I cd into a folder that is a Git repository I see something like the following prompt:
Notice the (master) notation. That is telling me I’m on the master branch. It’s just easier than issuing a “git branch” command everytime I want to know.
I know there are many other configurations out there, but I like to use the simplest thing that works.