I use git. I’m honestly shocked when someone doesn’t use git (or at least some DVCS) these days. It just seems somewhat draconian to use any of the legacy source control systems (albeit there are some rare exceptions, like game development graphics collateral). I was reminded of something by the great hands on session that Pamela Ocampo @pmocampo and Rachel @raychatter gave at OS Bridge titled “NerdCred++; How to Customize your Bash Prompt“.
After the session I dug into customizing my bash prompt. After doing a lot of manual editing I ended up just forking and implementing Michael Gonderman’s (@magicmonty) bash-git-prompt. The way to get this installed is pretty simple, albeit it does include a few steps (and yes, the README.md basically has the instructions, but I’ve copied them here just to discuss and for ease of readability). Another key points of reference include Sebastian Celis’s (@scelis) “A zsh prompt for git users“ on his blog.
First clone the repo (even though I’ve forked it I still pulled directly from
$ cd ~ $ git clone https://github.com/magicmonty/bash-git-prompt.git .bash-git-prompt
To verify that it is cloned ok, source the gitprompt.sh file from bash. It should immediately dive into a new prompt with a check mark and current directory, with the time immediately under that. Sweet, that worked!
$ source ~/.bash-git-prompt/gitprompt.sh ✔ ~ 10:48 $
Where the check mark is where git changes will display when navigating into a directory path that is a git repository and making changes. The format will look something like (
✔: repository clean ●n: there are n staged files ✖n: there are n unmerged files ✚n: there are n changed but unstaged files …n: there are n untracked files ⚑n: there are n stash entries ↑n: ahead of remote by n commits ↓n: behind remote by n commits ↓m↑n: branches diverged, other by m commits, yours by n commits
The next step is to make this permanent. Open up your ~/.bashrc file (or whichever you use, in my case I’m using ~./bash_profile, so be sure to figure out which one your system is using to actually load your bash). In the bash file add a single line to source the gitprompt.sh file.
# a bunch of other stuff in the file, whatever it might be... etc., etc. source ~/.bash-git-prompt/gitprompt.sh
I’ve added some links below that add additional options to customize your bash prompt (thank Pamela & Rachel). Even though all of this might seem like such a small little thing, having that extra information readily displayed on the prompt can be a huge time saver. Especially if you’re regularly in the code, committing from TDD or BDD practices or even just paired with somebody going through doing a refactor. It can be HUGE time saver, it definitely has for me.
…and thanks to ALL that gave me the motivation & for putting together the presentation and code for the prompt. Props to @scelis, @pmocampo, @raychatter & the others that have contributed to making bad ass bash prompts!
Pamela & Rachel’s Slide Deck & Additional Information: