Git aware bash prompt

Browsing for something on the google earlier today, I ran across a way to set up a git branch aware bash prompt. It’s pretty slick if you are always in and out of git branches (if you’re not you should be)

First download git-completion.bash
http://repo.or.cz/w/git.git?a=blob_plain;f=contrib/completion/git-completion.bash;hb=HEAD

I saved it as ~/.git-completion.bash.

Next edit your ~/.bash_profile

Add

source ~/.git-completion.bash
PS1='\h:\W$(__git_ps1 "(%s)") \u\$ '

Finally source ~/.bash_profile to make zee changes active.

What results is this when you are in a git repository:

bigtex:jason(jquery_localize) jason$ git checkout master
Switched to branch "master"
bigtex:jason(master) jason$ git checkout jquery_localize
Switched to branch "jquery_localize"
bigtex:jason(jquery_localize) jason$

Post a Comment