Git Bash with Git Branch and Status

Git Bash with Branch and Status Info

I found this great article on Intridea Development Blog on how to put git status in your prompt window. It’s an amazingly useful addon as I often forget what branch I’m on in my project or if I changed anything. The problem is that it’s written for OSX/Linux users. So I’d like to show you what you need to do to get this same functionality in Git Bash on Windows. (Git Bash using MSysGit)

To make this addon work with Git Bash you need to create your BASH settings file. To do this go to your home directory and create a file called ‘.bashrc’

Because Windows Explorer will not let you create a file without a name (only an extension) we need to use Git Bash (or command prompt): Open Git Bash (by default it will be in the home directory) and type in “touch .bashrc”

Inside your .bashrc file type this: (copied from Intridea Development Blog):

function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* (.*)/[1$(parse_git_dirty)]/"

export PS1='u:[33[0;32m]w[33[0;33m]$(parse_git_branch)[e[0m]: '

Now open a new Git Bash window and you should see your new prompt. Keep in mind it will not show up in folders that aren’t git repositories and it will slow down your prompt a bit because it has to check the status of your Git repository every time you hit ENTER.

Update: It seems the new version of msysGit comes with this feature built in

%d bloggers like this: