git ready

learn git one commit at a time
by Nick Quaranto

bash git status

committed 23 Jan 2009

Yeah, we all know about the git status command but that’s just way too many characters to type again and again. Why bother with those 10 keyboard strokes when you could have your shell simply output git’s working state? Sounds awesome, right? Luckily a few hackers have thrown together some scripts to do just this in your bash prompt. If you have these or similiar scripts working in other shells, submit a tip about it!

Probably the most widely used and known one shows your current branch name and if anything’s changed. Using this script in your .bashrc will give you a prompt like so:

# When clean...
user@host ~/dir[master]$

# When dirty...
user@host ~/dir[master*]$

So then it’s much easier to tell when you need to do a commit. You can check out plenty of variants of this script at Gist. This hack also evolved from showing just your branch name so feel free to build upon it or use it as you like.

Oh, you wanted more? Well, there is a neat project called git-prompt that can give you all sorts of information about the repository in your bash prompt. You can figure out if individual files are tracked or modified, figure out if merge conflicts are resolved, and even determine if your HEAD is detached. Check out the project page for more information on what it can do. Here’s a little demo of what it can show:

If you’ve got any other helpful prompt-related tips let us know and we’ll add it in!