How to show git branch name on console path

Many time when accessing your git branch from console becomes difficult. Here is a crisp post to show the git branch name on your console.

Add the below script in your bashrc file. Move to the end of the file and paste the below script snippet.

 

$ gedit ~/.bashrc


# Git branch in prompt.
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\] $"

git branch name on console<

Thats it. You should now be able to see the name of your branch on the console whenever you are inside the directory.

Yash Sharma is a Big Data & Machine Learning Engineer, A newbie OpenSource contributor, Plays guitar and enjoys teaching as part time hobby.
Talk to Yash about Distributed Systems and Data platform designs.

Leave a Reply

Your email address will not be published. Required fields are marked *