How to make a bash prompt with current git branch name

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


Originally posted at

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