How to Display your Local Git Branch in your BASH prompt

In order to make your life easier when working with git, this article provides the steps to display the current local git branch within your bash prompt. This not only saves you time, but also prevents the potential for human error by ensuring you are not making changes to the wrong branch.

Download Script

First all we download the git prompt script.

curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh -o ~/.git-prompt.sh

Update .Bashrc

We then add the following lines to ~/.bashrc

# import script
source ~/.git-prompt.sh

# customize/colorize prompt
export PS1="\e[37m\t\e[37m-\e[97m\u\e[92m\e[92m\w\[\033[m\]\e[96m\$(__git_ps1)\e[97m\$ "

Example

git-bash-example1

Rick Donato

Want to become a Linux expert?

Here is our hand-picked selection of the best courses you can find online:
Linux Mastery course
Linux Administration Bootcamp
and our recommended certification practice exams:
AlphaPrep Practice Tests - Free Trial