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.
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
Thanks for the information it was very helpful. For me %HOME% sounded like a generic variable and there is a chance some other applications may start using it, so I created a variable with name GITHOME instead of HOME. Did not observe any side effects so far!
Greg,
Great post..This got me out a jam when I was hitting “percent_expand: unknown key %H” when I was trying to push to a remote repository for the first time with a new project.
I was using Git Bash on XP
Thanks man…
I have been looking for this for two months….I feel a giant weight lifted from my shoulders. Thank you, Greg!
Thx for this tip. Great!
I did the dirty way without more environment variables – for single user modification:
“%HOMEDRIVE%%HOMEPATH%\My Documents\Projects Development”
Thanks, I was looking to manualy change it in git settings and your solution is so simple and effective :)
I made a small Video-Tutorial. The OS is in german, confusing to some, helpful to others ;)
Hope it helps, and thanks for this blog entry.
http://youtu.be/6KuiUqJZYGI
I’m abit of a NooB on how to manage bash profiles on a mac.
How would i make a $GITHOME variable and set the GITHUB default from $HOME to $ROOT/developer so that when i clone from github.com it puts the repo auto. in the latter?
This doesn’t really fix the problem if you type cd you still end up in %USERPROFILE% and not in %HOME%. A solution would change what Git bash understands to be $HOME