如何通过ssh从Windows计算机上进行git克隆? [英] How do I git clone from a Windows machine over ssh?

查看:126
本文介绍了如何通过ssh从Windows计算机上进行git克隆?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在Linux上执行ssh windowsmachine来访问Windows计算机,然后可以在其中git init --bare foo.git告诉我Initialized empty Git repository in C:/Users/unhammer/foo.git/

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/

但是我如何从Unix方面克隆它呢?

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.

以及/C:/Users/unhammer/foo.git/C/Users/unhammer/foo.git/Users/unhammer/foo.git.

请注意双引号:

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

当我尝试使用git clone linuxmachine:/some/path/that/does/not/exist.git时,这不会发生,然后git使用单引号引起来. (也许就是这个问题,是git-for-windows还是使用了额外引号的东西?)

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

推荐答案

最简单的解决方案是

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

在生效之前,您可能必须在Windows计算机上重新启动OpenSSH和/或终止来自客户端的现有ssh连接.现在,您无需任何额外的-u选项即可进行克隆:

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

(如果您之前指定了uploadpack/receivepack,请从.git/config中将其删除)

(and if you previously specified uploadpack/receivepack, remove them from .git/config)

这篇关于如何通过ssh从Windows计算机上进行git克隆?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆