How to make a bash prompt with current git branch name

Smart Gamma
Jun 7, 2016 · 2 min read
Image for post
Image for post

What is current branch of working repository?

Our company use some git branching rules base on “Continuous Integration” approach that we plan to describe soon as separate topic.

But our current topic is about how to setup a bash to display current git branch of working repository.

It will clearly indicate which current git branch we use now and won’t allow us make mistakes with merge actions etc that sometime happen before this feature was configured

So first,lets put these two files from github to your home dir:


Set permissions

$sudo chmod +x 
$sudo chmod +x .git-completion.bash

Then edit your .bashrc file

$vi ~/.bashrc

And put to end of the file:

if [ -f ~/.git-completion.bash ]; then
source ~/.git-completion.bash
source ~/
export PS1='[\u@\h \W]$(__git_ps1 "(%s)")\$ '

Then when you will navigate to some git repository you will see something like

Image for post
Image for post


Originally posted at

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store