git status in your bash prompt

1 minute read

I love git, but I found myself typing ‘git status’ all the time. The problem with that is that you can get anything from 2 lines to multiple screens of output depending on what you’re doing.

After seeing this blog I got the itch to put a little git info into my custom prompt. After several weeks of looking around at other solutions and tinkering on my own with an awk script I’ve come up with this:

One note, because this script pulls in so much information from git it can take some time to return a prompt for large repositories or across the network.

prompt1 My standard prompt

It starts with a hash (#) to make it a comment if it gets copy/pasted, host name in green, path in blue.

prompt2 A clean repository on the master branch

prompt3 A repository with some changes

The changes (in order from left to right): The local branch contains 1 commit not on the remote branch. There is 1 staged change (green), 2 unstaged changed (yellow), no unmerged changes (magenta), 4 untracked files (red), and 1 stashed change (in yellow on the right).

The code for my PS1 and the awk script are below.

Leave a Comment