Show Branch Name on Terminal

How can we show branch name anytime we’re running terminal on git directory (Linux). It make your steps easier without always typing git branch anytime you’d like to know on what branch you are in.


Open your ~/.bashrc on your favourite text editor.

Next you need to paste this code at the of the ~/.bashrc file:

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

If you would like to use another color, you can go to this link to learn more:

Apply your configuration without you having to logout/login by execute this command:

$ source ~/.bashrc


I wrote these tutorials for myself in future when I forget for the next steps.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store