My Macbook had a hardware failure recently and I ended up working on a Windows XP machine briefly. While configuring my development environment, I set up my working directory outside my Windows user profile directory (C:\Documents and Settings\Greg). How did Microsoft ever think ‘Document and Settings’ was a good path for user profiles?!
I needed to pull my company repository down from Github. msysgit was already installed. When starting gitbash to work with git, the default starting directory is %HOMEDRIVE%%HOMEPATH%, this translates to /c/Documents and Settings/Greg and not my working directory /c/greg/workspace/repo. Being a Linux/Mac guy I thought I might be able change my $HOME variable location but you won’t find a /etc/passwd file in msysgit’s emulation layer, and it won’t read .bash_profile or similar file early enough.
We have to do this the Windows way. Create a new environment variable and update the gitbash shortcut startup directory.
You can define a new environment variable by right clicking My Computer, select Properties and click the Advanced tab. At the bottom of this tab you’ll see a ‘Environment Variables’ button. Click this and define a new variable, HOME, with the value set to your working directory (in my case c:\greg\workspace\repo).
Now we can update our gitbash shortcut and use %HOME% to set the start up directory. Right click your gitbash shortcut and click Properties. Change the value of ‘Start in:’ field to %HOME%. Click OK.
Now when you open gitbash you’ll start in your working directory, no need to cd to it everytime.
You can skip to the end and leave a response. Pinging is currently not allowed.
comments
Awesome post. My company’s group policy had set my %HOMEDRIVE% to a network drive that was not writable. This allowed my to change it. Thanks.
Thanks for posting this, but a nice small tweak is to define
REPOPATH=\My Documents\Repo
and then update the shortcut to
%HOMEDRIVE%%HOMEPATH%%REPOPATH%
Nice tip.
very helpful – was seeing the default path set to an external network drive and this fixed it on the first try. Thank you
Thanks for the information, it works flawlessly.
OK, this may work on the first try, since gitbash will start in the specified path, indeed, but this does not resolve the git root reference.
next time you execute a command in gitbash, it will fall back to the root.
having the same case as Nick Wilcox (default path is a mapped network drive), that didn’t solve my problem.
lOVE U MY FRIEND .. WORKED LIKE A CHARM