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:

Similar Posts:

    None Found

Tags: , ,

7 Comments to “Show the Current GIT Branch in Your Command Prompt”

  1. Show the Current RVM Info in Your Command Prompt | DeveloperZen | February 7th, 2011 at 3:46 pm

    […] 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. Tom Bigelajzen | May 19th, 2011 at 11:39 am

    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\$ “

  3. Eran Kampf | May 19th, 2011 at 11:42 am

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

    Im currently using the updated gist here:

  4. Tom Bigelajzen | May 19th, 2011 at 11:49 am

    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


  5. Eran Kampf | May 19th, 2011 at 11:55 am

    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 :)

  6. Show the Current GIT Branch and Tag in Your Command Prompt | May 24th, 2011 at 5:03 pm

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

  7. Git a Reference | Marcio Garcia | August 11th, 2011 at 1:09 pm

    […] MAC: […]