Rizwan Mansuri's Blog
Python, Django & Linux

Adding git branch name into terminal prompt

t's always useful to keep eye on which branch you are working on. To get the branch name to terminal follow the step mentioned below.

Add following command to your .bashrc file.

parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
export PS1="\u@\h \[\033[32m\]\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\] $ "

Load the terminal and run the following command to reload the bash profile

source ~/.bashrc

You should able to see git branch in your terminal prompt