views:

149

answers:

2

I have successfully installed and configured msysGit Portable on my flash drive, and have used it to pull and push GitHub repos. However, I seem to always have to kludge the SSH support.

Specifically, in order for SSH to find my key files, I have to follow these instructions to start a second instance of ssh-agent and then ssh-add my key every time I run git-bash.bat.

Using the output of ssh -v [email protected] to debug I see that msysGit defaults to my Windows user directory to look for keys. It can't do that; I need it to look in its own directory on the portable drive.

How can I force $HOME to be the program's own folder?

+2  A: 

The command used to launch git bash is:

C:\Windows\SysWOW64\cmd.exe /c ""C:\Prog\Git\1.7.1\bin\sh.exe" --login -i"

I just tried the following in a DOS session:

C:\>C:\Windows\SysWOW64\cmd.exe /c ""C:\Prog\Git\1.7.1\bin\sh.exe" --login -i"
VonC@XXX /c/
$ echo $HOME
/c/Users/VonC

By default, $HOME$%HOMEPATH%, but if I force %HOME%:

set HOME=/another/path

and then launch the same bash session:

C:\>C:\Windows\SysWOW64\cmd.exe /c ""C:\Prog\Git\1.7.1\bin\sh.exe" --login -i"
VonC@XXX /c/
$ echo $HOME
/another/path

So if you wrap the bash call by a script setting the HOME to:

  • %~dp0 : the path of the wrapper on your USB key
  • or %~d1\your\path: with %~d1 being the drive letter (of your usb key if your wrapper is on it)

, you should be able to force HOME to whatever value you need.

VonC
Thank you very much. I'll try this out as soon as I can (on the road right now, but I'll have time at some point) and will accept your answer once I verify that it'll work. (I'd accept now, but it seems odd to accept an answer before verifying its correctness.)
Voyagerfan5761
@Voyager: no problem, take your time ;) I have had answer accepted after a long (very long) time before :) See the comments of http://meta.stackoverflow.com/questions/36318/whats-the-longest-interval-between-an-answer-being-posted-and-accepted
VonC
Great thread. :) I've just tested my wrapper and it totally worked like a charm. Only detail left is whether I can get the value of `%~dp0` without the trailing slashes; any ideas? If not, that's fine; my setup is still working great.
Voyagerfan5761
@Voyager: if you use a fixed path (always the same) in your USB, you ould use just `%d1` and build your path as you see fit. If not, you need to remove the last char, with DOS-based character substitution. See http://www.dostips.com/DtTipsStringManipulation.php. `set str=%str:-1%` should do it.
VonC
A: 

Hi, i'm also interested in the described functionality but not able to do so with the information given. Could you post your code ? I also think the guys at msysgit might like to change this too.

Contra-gamer
At some point I might write a blog post about my hack and/or fork msysGit to my own GitHub repo and include the change, but for now have a look at what I did with this wrapper script: http://gist.github.com/533267. It's worth mentioning that I also did an `ln -s ssh .ssh` within the msysGit Portable install directory so SSH keys stored in the `ssh` folder would work (and I didn't have to move them to a new `.ssh` folder).
Voyagerfan5761