Skip to content
jconnuck edited this page Apr 25, 2011 · 2 revisions

Add current branch to command prompt:

It's sometimes easy to forget which branch you are currently working in, which can cause some major headaches - so adding this code to your bash profile (~/.bash_profile or ~/.profile) will put the current branch in your command prompt when you are in a git directory.

Note: For some reason the colors (red = \ [\ 033[1;31m\], white = \ [\ 033[00m\]) aren't formatting correctly so I had to add extra spaces. If they don't work, try removing the spaces.

function bash_git_branch
{
  'git branch 2> /dev/null | grep \* | python -c "print '['+raw_input()[2:]+']'"$
}

PS1='\\ [\\ 033[00m\\]${debian_chroot:+($debian_chroot)}\u@\h:\w\\ [\\ 033[1;31m\\]$(bash_git_branch)\\ [\\ 033[00m\\]\$'

WHITE = \ [\ 033[00m\]
RED = \ [\ 033[1;31m\]

Clone this wiki locally