about me about me
photography photography
software projects software projects
contact me contact me
28
Feb

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?!

System Properties Advanced Tab in Windows XP is where you find the environment variables buttonI 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.

Change gitbash shortcut propertiesYou 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

David // 19.May.2011 // 17:55

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.

r_stitt // 28.Jun.2011 // 04:52

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%

mark // 18.Oct.2011 // 06:36

Nice tip.

Nick Wilcox // 29.Nov.2011 // 21:33

very helpful – was seeing the default path set to an external network drive and this fixed it on the first try. Thank you

Wenhui // 29.Jan.2012 // 03:59

Thanks for the information, it works flawlessly.

Eliran Malka // 22.Feb.2012 // 20:49

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.

WOWBOW // 19.May.2012 // 15:28

lOVE U MY FRIEND .. WORKED LIKE A CHARM

Naga // 06.Jun.2012 // 15:38

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!

FC // 09.Jun.2012 // 10:14

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…

rsgracey // 15.Jun.2012 // 13:48

I have been looking for this for two months….I feel a giant weight lifted from my shoulders. Thank you, Greg!

MatthiasDE // 29.Aug.2012 // 18:52

Thx for this tip. Great!

I did the dirty way without more environment variables – for single user modification:
“%HOMEDRIVE%%HOMEPATH%\My Documents\Projects Development”

Andrew // 26.Dec.2012 // 15:34

Thanks, I was looking to manualy change it in git settings and your solution is so simple and effective :)

Dochi // 10.Jan.2013 // 21:47

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

J // 11.May.2013 // 05:19

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?

Mark // 03.Apr.2014 // 17:43

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

this post's tags