Git branch in your bash prompt
January 18, 2010, 1:31 pm
Filed under: Uncategorized

While trying to work out how the excellent tab completion works for git, I found /etc/bash_completion.d/git which mentions the __git_ps1 command, you can use this to put the current branch in your bash prompt

here’s mine:

PS1='${debian_chroot:+($debian_chroot)}\[\ 033\[01;34m\]
\u@\h\[\ 033\[00m\]:\[\ 033\[01;33m\]\w\[\ 033\[1;32m\]
$(__git_ps1 " (%s)")\[\ 033\[00m\]$ '

(Remove the space from \ 033, WordPress wouldn’t escape it properly)

The magic bit being

$(__git_ps1 " (%s)")

There are a couple of options you can set too to get it to show you the status of the repo too, see the file above for more info.


Leave a Comment so far
Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: