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-prompt.sh:

~/code/git/contrib/completion(master) > ls
total 96
-rwxr-xr-x  1 user  staff    44K Apr 14 15:26 git-prompt.sh

I copy this file to my $HOME folder as .git-prompt.sh and then reference it and the ps1 propt feature in my .bashrc file

source ~/.git-prompt.sh
export PS1='w$(__git_ps1 "(%s)") > '

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

~/gitosis-admin(master) >

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.

Comments

Daniel Hölbling: I use something similar for my powershell prompt: http://www.tigraine.at/2010/05/16/displaying-git-branch-in-your-powershell-prompt/ greetings Daniel

derick.bailey: @Daniel - you should check out Posh-Git. it’s a very complete powershell git integration. http://github.com/dahlbyk/posh-git

Jason Meridth: @Daniel Nice. @Derick Thanks for the info. I’d heard about it, but hadn’t looked yet.

3KWA: missing in front of w

Jason Meridth

jmeridth

My name is Jason Meridth. I am a continuously learning senior software developer/devops/team lead/development manager trying to not let best be the enemy of better. I reserve the right to change my mind upon obtaining more information. I am also the owner and principal software consultant at Meridth, LLC. If you have any software, hardward, networking, process, etc needs please don't hesitate to reach out to me.

Raspberry Pi Kubernetes Cluster - Part 2

Howdy again.Alright, my 8 port switch showed up so I was able to connect my raspberry 3B+ boards to my home network. I plugged it in wit...… Continue reading

Raspberry Pi Kubernetes Cluster - Part 1

Published on April 07, 2018

SSH - Too Many Authentication Failures

Published on March 28, 2018