16

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

3
  • 1
    This depends a little bit on the ssh server you use. See stackoverflow.com/a/8050564/7976758. Try git clone ssh://windowsmachine/Users/unhammer/foo.git.
    – phd
    Commented Dec 18, 2018 at 18:24
  • It's the builtin Windows 10 one (Setting→Apps & Features→Manage optional features→Add a feature→OpenSSH server). There was a bit off fiddling to get it set up, but I can scp -r windowsmachine:/Users/unhammer.foo.git, while git clone ssh://windowsmachine/Users/unhammer/foo.git fails (''/Users/unhammer/foo.git'' does not appear to be a git repository).
    – unhammer
    Commented Dec 19, 2018 at 8:18
  • Indeed, it happens because the default windows shell interprets single quotes as literals, and git always sends single quotes around it's arguments to the remote shell
    – iPherian
    Commented Dec 15, 2019 at 9:25

2 Answers 2

23

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)

2
  • 1
    Nice, worked for me, but had to run powershell as admin.
    – joshbodily
    Commented Mar 2, 2022 at 3:37
  • It seems easier to me to just use regedit and set the value. That way I can see if the value was already set and save it if needed. Commented Aug 16, 2023 at 7:03
2

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.

1
  • 1
    This is the best answer here. With more modern versions of Git on Windows, this should be git receive-pack (i.e. the receive-pack subcommand of git) and git upload-pack.
    – rain
    Commented Dec 10, 2023 at 22:05

Not the answer you're looking for? Browse other questions tagged or ask your own question.