I work with git command in terminal a lot and I often forget what branch I was working on. Running command git branch
often is not very convenient I needed to put git branch in command prompt when I was inside git repository.
I wanted my console to look like this:
eanlr@vps some-repository (master) $
To get that you need to add following lines to your .bash_profile file in your home directory:
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^*/d' -e 's/* (.*)/ (\1)/'
}
export PS1="\u@\h \W[\033[32m]$(parse_git_branch)[\033[00m] $ "
You can of course customize command prompt by changing PS1 variable.