Skip to content

Make your bash aware of git branch on Ubuntu

July 3, 2008

If you’re someone who has multiple  git branches on a project and seem to always do git branch to check which branch you’re in. Then here’s how you can make your bash aware of a git branch.

Well, I’m not sure if this works on others, but it sure does works in my Ubuntu Hardy. Just edit your .bashrc at your home folder.

vim .bashrc

Add the following at the very bottom of your .bashrc

parse_git_branch() {
  git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
PS1="${debian_chroot:+($debian_chroot)}\u@\h:\w\$(parse_git_branch) $ "

After that, save it and restart your terminal. You should see something like this at your terminal:

fadhli@atlantis:~/projects/crimson_mdec(master) $

I have a branch named biz_idea, so after a git checkout biz_idea

Switched to branch “biz_idea”
fadhli@atlantis:~/projects/crimson_mdec(biz_idea) $

No comments yet

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: