Wednesday, October 27, 2021

[SOLVED] How do I git clone from a Windows machine over ssh?

Issue

I can do ssh windowsmachine from Linux to access a Windows machine, and from there I can git init --bare foo.git, telling me Initialized empty Git repository in C:/Users/unhammer/foo.git/

but how do I clone that from the unix side?

$ git clone ssh://windowsmachine:foo.git
Cloning into 'foo'...
fatal: No path specified. See 'man git-pull' for valid url syntax

$ git clone ssh://windowsmachine:C:\\Users\\unhammer\\foo.git
Cloning into '\Users\unhammer\foo'...
fatal: No path specified. See 'man git-pull' for valid url syntax

$ git clone ssh://windowsmachine:/foo.git
Cloning into 'foo'...
fatal: ''/foo.git'' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

and similar messages for /C:/Users/unhammer/foo.git and /C/Users/unhammer/foo.git and /Users/unhammer/foo.git.

Note the double single-quotes:

fatal: ''/Users/unhammer/foo.git'' does not appear to be a git repository

This doesn't happen when I try to git clone linuxmachine:/some/path/that/does/not/exist.git, then git uses single single-quotes. (Maybe that's the issue, git-for-windows or something applying extra quotes?)


Solution

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)



Answered By - unhammer