Show the Current GIT Branch in Your Command Prompt

One fo the most confusing things when working with multiple branches on git is having to remember the branch you’re currently working on.
Typing git branch all the time is annoying…

Thats why I’ve set my shell’s prompt to display the current branch!
Just add the following to your  ~/.profile file:

You may also like...

7 Responses

  1. Nice job!

    I improved this on my Mac to:

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


    PS1=”$LIGHT_GRAY\u@\h$NO_COLOR:\w$GRAY\$(parse_git_branch)$NO_COLOR\$ “

  2. Eran Kampf says:

    Whats the change? can you show how your command prompt looks like?

    Im currently using the updated gist here:

  3. 3 changes:
    1. I don’t like colors in my terminal so i added another 2 shades of gray
    2. replaced ‘machine’ with \h wich pritns the host
    3. changed ‘s/* \(.*\)/ (\1)/’ to ‘s/* \(.*\)/[\1]/’

    the result is


  4. Eran Kampf says:

    Personally I think the (my) host is too long to print in every line…

    Your comment reminds me I should really start blogging again.
    People might think I’m a .NET dev :)

  1. February 7, 2011

    […] manage the Ruby versions and Gem sets of the different projects I’m working on. So, much like showing the current Git branch, its really useful to show the current RVM environment as part of the command prompt. So I just […]

  2. May 24, 2011

    […] Eran’s post on showing current git branch, here is an improved version including branch or tag number (which is helpful in repositories […]

  3. August 11, 2011