Detached git status line

It’s been a really long time since I posted about a prompt with git status support built in. I don’t care so much about svn these days, but something that has bothered me for quite a while about the default git status line is that it’s pretty useless if you aren’t at the tip of a branch. The default __git_ps1 function simply returns the sha of the current commit. It’s really unhelpful to simply see (abc1234...), especially when you’re doing a git bisect or something like that.

Instead of just using __git_ps1, you can spruce up your git prompt to tell you exactly where you are! Git knows that commit abc1234 is actually master~2 or feature_branch~25. Wouldn’t it be more helpful to see that?

After some agonizing, I’ve managed to glue together a couple of git commands that actually provide that extremely useful information. There was a minor bug that put “master” in the prompt if you had just created a new branch, but I got that fixed too.