Skip to content

Show current git branch

twitter logo github logo ・1 min read  

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\]\$ "

Originally published in

twitter logo DISCUSS (1)
Classic DEV Post from Nov 22 '19

What Status Page Provider or Project Do You Recommend?

What status page provider or project do you recommend?

Czar Pino profile image
Hi there. I'm Czar Pino. I studied computer science and now write programs for the world-wide web. I enjoy working with PHP7, Symfony, and Docker.

Sore eyes? now has dark mode.

Go to the "misc" section of your settings and select night theme ❤️