[JT] Jochen Topf's Blog
Sun 2014-11-09 18:07

Git Info in The Shell Prompt

I am a heavy git user. I am actively developing in about half a dozen repositories at the same time and have many more I occasionally check out or add to. I have files lying around that need to be added, changes to be committed, commits to be push, all in several branches, local and remote. And then there is the stuff I stashed months ago and forgot…

Here is a little tip that might help you, too:

To see a bit better what is happening in my git repositories I have changed my shell prompt. If my current directory is in a git repository, a short overview of that repository is shown. This includes the name of the currently checked out branch (most often master) and a set of (Unicode) characters for different states of the repository:

Of course I could have used some simple characters, but digging around the Unicode code chart to find appropriate icons was fun. :-)

So far this has been very useful. I don’t forget any more to push my commits at the end of the work day and I am constantly reminded that there are stashed files I need to clean up. I am still experimenting to improve on this. I am thinking for instance about extending the ‘remote repository’ check, some repositories don’t usually have any extra remotes, others usually have, so it would be useful to include this in the check. Maybe you have some ideas, too!

The code for all of this is on Github. I am using zsh, but I am sure something similar would be possible with Bash or other shells.

Tags: dev · git · zsh