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
Latest posts by Rick Donato (see all)
- How to Configure a BIND Server on Ubuntu - March 15, 2018
- What is a BGP Confederation? - March 6, 2018
- Cisco – What is BGP ORF (Outbound Route Filtering)? - March 5, 2018
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