Git for Windows tip: Setting shell aliases with msysgit

As msysgit uses a bash shell, you can set really handy aliases for the different git commands. For example gs instead of git status and ga instead of git add are the ones I use the most. Check out the great Git Immersion tutorial from Edgecase for a list of aliases. I can also recommend creating the got and get aliases. It’s amazing how often I write got instead of git.

Using the bash shell can be unfamiliar to a Windows user. So if you want to set aliases in msysgit it is not very obvious where they should go. They could go into the .bashrc file or the bash_profile file. From a linux perspective the bash_profile configuration file is executed when logging in while the .bashrc file is executed every time a bash shell window is opened. The .bashrc file is located in the c:\Users\YourUsername directory and the bash_profile file is in the etc directory. In the case of msysgit I fail to see that there is any real practical difference; both are executed when you start up msysgit. So I just used .bashrc and it works great.

If there is no file named .bashrc then you’ll have to create it. Windows 7 will not allow you to create a file with a dot (period) as the first character in the filename and with no extension. So the easy way to do this is to name your file .bashrc. (with an extra dot at the end) and Windows will automatically rename the file to just .bashrc (with no dot at the end).

My .bashrc file (almost identical to the Git Immersion profile file that is linked above):

alias less='less -r'
# --show-control-chars: help showing Korean or accented characters
alias ls='ls -F --color --show-control-chars'
alias ll='ls -l'
alias gs='git status '
alias ga='git add '
alias gb='git branch '
alias gc='git commit'
alias gd='git diff'
alias go='git checkout '
alias gk='gitk --all&'
alias gx='gitx --all'
alias got='git '
alias get='git '

9 thoughts on “Git for Windows tip: Setting shell aliases with msysgit

  1. Thanks for this post. I think I may have found a better and perhaps more correct way of doing it. Simply, go to your home directory, (C:\Users\) and if it doesn’t already exist, create a file named “.gitconfig” (notice the leading dot). Then open this file in some kind of text editor and add this section to it. (spacing doesn’t really matter.)

    [aliases]
    co = checkout
    ci = commit
    st = status
    br = branch

    That’s it. Save and exit. If you want to add other aliases or change these go ahead and do that. Now if you write git st, it will be read as git status. :)

    1. Those aliases are git aliases and not bash aliases and thus would still require putting ‘git’ in front of them to run.

  2. I am trying to create one bash profile with sublime 3 and few changes. Windows is returning an error whenever I tried to change the name of the bash file to .bash file, searched google ad stack overflow.. I guess I am the only one.
    Any help on that>?

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s