Show current git branch

czarpino

Czar Pino

Posted on September 6, 2018

Show current git branch

During development, it can be quite convenient to always know which branch you are on without having to do a git status. Most developers use unnecessarily sophisticated bash scripts to modify the prompt string 1 (PS1) variable of their shell. As embarrassing as it is, I was most developers (I even had my own repo with a "performance" focused approach). Now, I simply use a one-liner. In fact, I just visit this article and copy paste the following into my ~/.bash_profile:

# Show current git branch when entering a git repository
export PS1="\W \[\e[0;36m\]\$(git rev-parse --abbrev-ref HEAD 2> /dev/null)\[\e[0m\]\$ "
Enter fullscreen mode Exit fullscreen mode

Originally published in https://plog.czarpino.com/show-current-git-branch/

💖 💪 🙅 🚩
czarpino
Czar Pino

Posted on September 6, 2018

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related