Press "Enter" to skip to content

Git for Windows – .bashrc configuration

I have heavily modified my Bashrc configuration. This article shows how you can make better use of Git and the command line.

.bashrc file:
If you are using GitBash, Cmder, ConEmu, or some other GUI client the .bashrc file is important to understand. The purpose of this file is to enable you to create aliases (naming shortcuts) and functions in Git.

The .bashrc file is located in ~/.bashrc. Make sure to backup this file and the ~/.gitconfig file before making any manual changes.

As an example, instead of typing “git status -s” I have defined an alias that allows me to type “gst” to save some typing. The functions I describe below will save even more time and typing.

Another trick that I’ve added into .bashrc is color coding of the prompt to show the current checkout status and branch of the Git repo.

See the image below:
Git console window

The first prompt shows an example where I am not currently in a Git repo and the prompt only shows the text “git /c/src/github”.

Once I have changed directories into the Pester repo (a nice PowerShell Unit Testing library), you can see that the prompt has changed to “git (master) smiley /c/src/github/Pester”. The green color for the “(master)” text and smiley signifies that nothing has been modified in this repo. The “(master)” text means that I am currently working on the master branch.

After modifying README.md in the vi editor, you can see that the prompt’s color changes to red around the branch name “(master)” and the smiley icon changes to a check mark (meaning something is checked out). This is a trick that I learned from Celogeek blog.

One note of warning. This prompt change does add some overhead to each command that you do, due to the “git status” required to color code the branch. If you have a slow connection or a small amount of memory on your computer, you may want to consider removing this feature. To remove it, delete the PS1 export statement from the script below.

I’ve added my .bashrc below (note that you’ll need to change the Global variables in the top of the file). These aliases coupled with the changes to the ~/.gitconfig described later saves a lot of typing and allows you to use Git with windows more naturally.

Note, I’ve referenced in the comments some webpages that I have learned from, like MediaDoneRight and Celogeek.

Configuring basic aliases in the ~/.gitconfig
Before you see some of the above aliases work, you need to edit your .gitconfig file and add some values below. You can edit the .gitconfig file by using the gitconfig command from above it the ~/.bashrc file.

Debugging the config files
A cool trick while editing the .bashrc and .gitconfig files, is to use the following command to see any errors that it generates. It is handy for debugging:

I hope that some of the techniques above help you to enhance your Git experience in Windows.

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *