Ubuntu: Show current Git branch on Terminal prompt


There are times when I keep running git status or git branch to check which branch I’m on and I just found that I could do something to show the name of my current Git branch on my Terminal prompt, thanks to a colleague.

In the following screenshot I’m working in the directory “sample_app”, on Git branch that is named “static-pages”:

ubuntu-terminal-prompt-git-branch-

In Ubuntu, here’s how I did it.

Create .bash directory in Home:
mkdir ~/.bash

Go to the new directory
cd ~/.bash

Clone the git-aware project from GitHub:
git clone git://github.com/jimeh/git-aware-prompt.git

Edit your .bashrc file. I use Vim editor for this:
vim ~/.bashrc

Add the following to the top of your .bashrc:

If you want colored prompts, add the following to the bottom of your .bashrc:

Otherwise, if you doon’t like colors, use this instead:

Open a new Terminal tab or restart Terminal. Navigate to any directory that has a Git repository and your Ubuntu’s Terminal prompt should now show the current Git branch’s name.

Catzie

A Filipino who is a mobile & web developer on weekdays, and a baker on weekends. When I have time to spare, I blog, play video games, watch series (usually anime), cook dishes, draw, or spend a little time with pets. When I have the rare luxury of time, I get to travel and record song covers too! Follow on Twitter: @catzie

Leave a Reply

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