Time needed: 2 minutes.
In this Article will learn how to show git branch name with color in terminal (ubuntu)
- Open bashrc file
Firstly open bashrc file by below cmd.
- Comment old color prompt
In ~/.bashrc file, you will find a code starting with if[“$color_prompt = yes”] and end’s with fi, just comment this like as shown in below screenshot for reference.
- Add below line of code
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
if [ "$color_prompt" = yes ]; then
- Final done
Here is how your terminal shows branch name when you are into git repository project folder, In below screenshot as you can see we can easily get to know on which github branch we are working on(No need to keep on checking git branch -a).