Archive

Posts Tagged ‘git dirty state’

Show current git branch on your bash prompt

September 8, 2015 Leave a comment

I started learning to use git and the examples I saw showed the branches on the command prompt which I think is very cool and helpful. And of course, I wanted that too.

In 3 simple steps.

1. Download
curl https://github.com/git/git/raw/master/contrib/completion/git-completion.bash -OL
2. Add the following to .bashrc

# Add Git configurations
source git-completion.bash
export PS1='\[\033[1;34m\]\!\[\033[0m\] \[\033[1;35m\]\u\[\033[0m\]:\[\033[1;35m\]\W\[\033[0m\] \[\033[1;92m\]$(__git_ps1 "(%s)")\[\033[0m\]\$ '
export GIT_PS1_SHOWDIRTYSTATE=1

3. Restart your terminal so that the changes take place or source your bashrc YMMV.

This is just the tip of the iceberg. You can get much much more at the resources listed below
Source:

http://blog.taylormcgann.com/2012/06/19/show-current-git-branch-your-bash-prompt/#comment-12515
http://thepugautomatic.com/2008/12/git-dirty-prompt/

Advertisements