Git and Bash Love

I’ve recently been working with git a lot, more specifically with branches. I love git’s branching and its fairly awesome. However, its also easy to forget which branch you’re currently working on (especially awful to find that the commits you did were to master :/). Sometime back I did some extensive searching to fix that situation and finally stumbled upon a neat way to fix it. I modified the PS1 variable to show the current branch! Here’s what I added to the .bashrc file in Ubuntu 🙂

function parse_git_branch {     ref=$(git symbolic-ref HEAD 2> /dev/null) || return     echo "("${ref#refs/heads/}")" }  RED="[33[0;31m]" YELLOW="[33[0;33m]" GREEN="[33[0;32m]"  PS1="$PS1$RED$(date +{13371f13f0bf161e7595c2ac5df92e005bed3de1d132ef646d0a44f3a1a9ee62}H:{13371f13f0bf161e7595c2ac5df92e005bed3de1d132ef646d0a44f3a1a9ee62}M) w$YELLOW $(parse_git_branch)$GREEN$[33[0m] " 

Leave a Reply