Show Branch Name on Terminal

Fiko Borizqy
1 min readMay 27, 2019

--

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.

Configuration

1. Open ~/.bashrc

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

2. Paste Configuration Code

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\$ "

3. Custom Color

If you would like to use another color, you can go to this link to learn more: https://www.shellhacks.com/bash-colors/

4. Apply Configuration

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

$ source ~/.bashrc

— FINISHED —

--

--

Fiko Borizqy
Fiko Borizqy

Written by Fiko Borizqy

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

Responses (1)