Seeing which Git branch I’m on via my console prompt (__git_ps1)

 

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://git.kernel.org/pub/scm/git/git.git

There is a file in the contrib/completion folder called git-completion.bash:

~/code/git/contrib/completion<span class="o">(</span>master<span class="o">)</span> > ls
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 propt feature in my .bashrc file

<span class="nb">source</span> ~/.git-completion.bash
<span class="nb">export </span><span class="nv">PS1</span><span class="o">=</span><span class="s1">'w$(__git_ps1 "(%s)") > '</span>

And now whenever I cd into a folder that is a Git repository I see something like the following prompt:

~/gitosis-admin<span class="o">(</span>master<span class="o">)</span> >

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.

 

Related Articles:

Post Footer automatically generated by Add Post Footer Plugin for wordpress.

About Jason Meridth

Continuously learning software developer trying to not let best be the enemy of better
This entry was posted in git. Bookmark the permalink. Follow any comments here with the RSS feed for this post.

4 Responses to Seeing which Git branch I’m on via my console prompt (__git_ps1)

  1. @Daniel – you should check out Posh-Git. it’s a very complete powershell git integration.

    http://github.com/dahlbyk/posh-git

  2. @Daniel

    Nice.

    @Derick

    Thanks for the info. I’d heard about it, but hadn’t looked yet.

  3. 3KWA says:

    missing in front of w