How do I git clone from a Windows machine over ssh?
Following @phd's link to https://stackoverflow.com/a/8050564/7976758 I found a reference to https://stackoverflow.com/a/2323826/69663 with a workaround to the quoting issue. Here's what I did:
On Windows, open Git Bash and, in my homedir:
echo 'git-receive-pack "$@"' >grp.sh
echo 'git-upload-pack "$@"' >gup.sh
On Linux, clone specifying upload-pack:
git clone -u '"C:/Program Files/Git/bin/bash.exe" gup.sh' ssh://windowsmachine/c/Users/unhammer/foo.git
cd foo
git config remote.origin.uploadpack '"C:\Program Files\Git\bin\bash.exe" gup.sh'
git config remote.origin.receivepack '"C:\Program Files\Git\bin\bash.exe" grp.sh'
So the repo path is the one that Git Bash shows (/c/Users/$username/$repo
), no colon anywhere.
https://github.com/PowerShell/Win32-OpenSSH/issues/1082 seems related.
The easiest solution is to change the default Windows OpenSSH shell to bash. You can do this easily from powershell on the Windows machine:
powershell
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Program Files\Git\bin\bash.exe" -PropertyType String -Force
You may have to restart OpenSSH on the Windows machine and/or kill existing ssh connections from the client before it takes effect. Now you can clone without any extra -u option:
git clone ssh://windowsmachine/c/Users/unhammer/foo.git
(and if you previously specified uploadpack/receivepack, remove them from .git/config)