Display Current Git Branch for Mac Bash iTerm

As a developer using git, it’s always good to know which branch you’re currently on. I wish I’ve done this a lot earlier but I now have the following snippet pasted into my ~/.bash_profile. Some other blog posts have this snippet in ~/.bashrc, some in ~/.profile. To be honest, I’m not exactly sure of the difference between each one, even after reading stuff like his: http://stackoverflow.com/questions/415403/whats-the-difference-between-bashrc-bash-profile-and-environment.

So if you open a new terminal and nothing happens when you go into a folder that has been git initialised, you might need to paste the code in one of the other files.

parse_git_branch() {
	git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(git::\1)/'

PS1="\[33[00m\]\u@\h\[33[01;34m\] \w \[33[31m\]\$(parse_git_branch) \[33[00m\]$\[33[00m\] "

Source: http://asemanfar.com/Current-Git-Branch-in-Bash-Prompt

4 thoughts on “Display Current Git Branch for Mac Bash iTerm

  1. My coder is trying to convince me to move to .net from PHP.
    I have always disliked the idea because of the costs.
    But he’s tryiong none the less. I’ve been using Movable-type on a number of websites for about a year and am concerned about
    switching to another platform. I have heard excellent things about
    blogengine.net. Is there a way I can transfer all my wordpress content into it?
    Any help would be greatly appreciated!

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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