If you’re using git properly and collaborating on a project, chances are you find yourself changing branches often. This can be quite disorienting. You deploy from the master branch, then get back to that bug fix you were about to work except for—whoops!—now you commited that fix to master and have to back away slowly. Confusions like this one can easily be avoided by putting you branch name front-and-center: at the end of your bash prompt. Here’s how.
git-promt.sh script here.
Put it somewhere like
If you want to be all CLI about it, you could just run:
Now modify your your bash profile (it’s at
~/.bash-profile, in case you’re new to this stuff).
Before the part of the file that declares what your prompt will look like (
PS1=[...]), load in the script you just downloaded, like so:
\$(__git_ps1) to your prompt declaration.
You can put it wherever you like, but I think it’s best suited for the very end, right before the final dollar sign (
If you want to get all fancy, you can make it a pretty color.
My declaration looks like this:
(See here for color definitions.)
This declaration results in a prompt looks like this when I’m in the directory
~/src/food52 and on the branch
That’s it. Never git lost again!