fir3net
PPS-Firenetbanner-780.5x190-30-03-17

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

Tags: Github, BASH, Git

About the Author

RDonato

R Donato

Rick Donato is the Founder and Chief Editor of Fir3net.com. He currently works as a Principal Network Security Engineer and has a keen interest in automation and the cloud.

You can find Rick on Twitter @f3lix001