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.

Related Posts:

Posts that may be related to "Ubuntu: Show current Git branch on Terminal prompt":

Catzie

An odd human being who happens to have a variety of ever-changing interests, but right now they are programming, making up silly song/rap lyrics, K-pop, drawing, creating unique dessert/drink flavors, obsessing about finding out how some things works, automation, anime, video games... Ran online dessert shops Cookies PH and Catzie's Cakery in her past life.

Leave a Reply

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