Ubuntu: Show current Git branch on Terminal prompt

Written by

in

, ,


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.

Related Posts

Comments

Leave a Reply

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