Oliver
Oliver

Reputation: 146

Why do Git commands fail via Win32-OpenSSH on Windows 10?

I have set up Win32-OpenSSH on a Windows 10 system, and I am using Git for Windows 2.16.1.
I have created a bare test repository, from which I can clone just fine via the file URL:

git clone file:///c:/test.git
Cloning into 'test'...
remote: Counting objects: 33, done.
remote: Compressing objects: 100% (32/32), done.
remote: Total 33 (delta 11), reused 0 (delta 0)
Receiving objects: 100% (33/33), done.
Resolving deltas: 100% (11/11), done.

SSHD is also running fine, I can open a shell from my tablet, and access the repository directory via SFTP:

> sftp oli@localhost
oli@localhost's password:
Connected to oli@localhost.
sftp> pwd
Remote working directory: /C:/Users/Oli
sftp> cd /c:/test.git
sftp> pwd
Remote working directory: /c:/test.git
sftp> ls
HEAD  config  description  hooks  info  objects  packed-refs  refs
sftp> bye

But cloning via SSH fails for some reason:

> git clone ssh://oli@localhost:22/c:/test.git
Cloning into 'test'...
oli@localhost's password:
fatal: ''/c:/test.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.

User "Oli" definitely has the correct access rights, and we have seen above that the repository exists and is a valid Git repository. I also tried many different syntax variants on the path.
I have read every Q/A here on Git/SSH/Windows, and the Git Pro book, and the Git reference, and the OpenSSH manuals, and the Win32-OpenSSH wiki.

What am I missing?

Upvotes: 1

Views: 568

Answers (1)

Oliver
Oliver

Reputation: 146

This has been answered by Konstantin in this question (Thanks for the link, Aurel):

The problem is - cmd.exe doesn't understand single-quoted parameters.

Git passes the path to the repository enclosed in single quotes, which does not work in cmd.exe.
This can actually be seen in the Git error message above, if you look close enough:

fatal: ''/c:/test.git'' does not appear to be a git repository

So I have set up the workaround that Konstantin suggested:

  • create shell scripts gup.sh and grp.sh in my home directory on the server, each containing the single line git-upload-pack.exe $* resp. git-receive-pack.exe $*
  • use parameter -u 'sh gup.sh' in the initial clone operation (when doing this in cmd.exe, use double quotes...)
  • configuring the cloned repository with commands git config remote.origin.uploadpack 'sh gup.sh'and git config remote.origin.receivepack 'sh grp.sh'

...and it works.

Sadly, Konstantin's answer is not the accepted one, and the least upvoted one. So if this helps you, too, upvote his answer!

Upvotes: 2

Related Questions