Git for Windows tip: Setting $HOME and the startup directory

Git for Windows opens bash in the the user profile directory per default and I wanted to change it to the directory with my Github projects instead. I had to try a couple of approaches before finding the solution.

Setting $HOME

The first approach I tried was setting the $HOME environment variable. There are a couple different ways of doing this (like messing around with the etc/profile file) but easiest for me was using Windows’ environment variables as Git for Windows/msysgit has access to them. The Home directory for msysgit is set to the Windows environment variable %USERPROFILE%  if no $HOME variable exists. So just create a $HOME environment variable in Windows (see screenshot below)  and msysgit bash will use that as the default. Now you can use the command cd $HOME to go directly to your new home directory.

EVCapture

But msysgit still opens up in my user profile directory…

Unfortunately, this does not help with the startup directory problem. The solution is actually really simple. Right-click on the msysgit shortcut and in the Start in field, enter your desired startup directory. Easy if you know how.

msysgitCapture

12 thoughts on “Git for Windows tip: Setting $HOME and the startup directory

    1. Actually in Win10 it works just perfect wth only HOME variable since the value “start in” in the shortcut’s properties is by default: %HOMEDRIVE%%HOMEPATH% .
      In initial state (no home directory variable) it’s mapped like that:
      “%HOMEDRIVE%” -> “C:\”
      “%HOMEPATH%” -> “Users\{Your username}”.
      And same if you have your home directory anywhere you want, eg. on other drive in a custom folder, so if the $HOME is, let’s say “D:\work\sth\somewhere” it would be:
      “%HOMEDRIVE%” -> “D:\”
      “%HOMEPATH%” -> “work\sth\somewhere”.
      But that’s in Win10 ;)

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