【问题标题】:Git clone on windows : git@github.com is not a git commandWindows 上的 Git 克隆:git@github.com 不是 git 命令
【发布时间】:2021-03-11 15:23:52
【问题描述】:

我正在尝试通过 ssh 方式从 github 和另一种形式的 gitlab 克隆存储库

我在 Windows 上编辑:使用 Git v 2.29.2.2

我收到以下错误,我不明白它的来源:

$ git clone git@github.com:math-gallou/AI21_TPs.git
Cloning into 'AI21_TPs'...
git: 'git@github.com' is not a git command. See 'git --help'.
fatal: Could not read from remote repository.

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

所以我也试过了:

$ git clone "ssh://git@github.com:math-gallou/AI21_TPs.git"

$ git clone ssh://git@github.com:math-gallou/AI21_TPs.git

但同样的错误出现了。

当我执行ssh -v git@github.com 时,我可以成功连接。

那么我错过了什么?

【问题讨论】:

  • 你安装了哪个版本的 Git-for-Windows?
  • 提示(也许没有帮助,但无论如何):ssh:// URL 的语法略有不同:git clone ssh://git@github.com/math-gallou/AI21_TPs.git(斜杠 / 而不是冒号 :)。见git-scm.com/docs/git-fetch#_git_urls

标签: windows git ssh clone


【解决方案1】:

在我的例子中,我定义了系统环境变量 GIT_SSH 来使用我安装的 openssh,然后 git 坏了,我得到了git: 'git@github.com' is not a git command. See 'git --help'.

删除系统环境变量 GIT_SSH 后一切正常。

然后我尝试定义 user 环境变量 GIT_SSH 并重新启动系统(我在之前的尝试中没有重新启动系统),不知何故,现在我的 git 与我安装的 openssh 一起正常工作。我不知道在我之前的尝试中哪个部分错了,但我决定不再在这上面浪费更多时间。

【讨论】:

    【解决方案2】:

    首先,如果您尝试使用 ssh:// 语法,那么 URL 将是:

    git clone ssh://git@github.com/math-gallou/AI21_TPs.git
                                ^^^ /, not :
    

    其次,检查您是否有一个%USERPROFILE%\.ssh\config 文件,其中包含github.com 主机条目,其内容可能不正确或被误解。

    【讨论】:

    • 所以我首先尝试了你给我的语法,但仍然显示完全相同的错误。其次,我没有这个配置文件,我看看它是什么以及它应该包含什么
    • @mathoug 好的,配置文件怎么样?
    • 嗨@VonC。我在这篇文章之后做了配置文件:stackoverflow.com/questions/56287059/…。它完全没有改变。和一个朋友一起,我们在某个地方想了一个奇怪的别名?但我试图清理我的 git install (删除并重新安装所有内容),它仍然是一样的......:/
    • @mathoug 你能用简化的 PATH 试试吗? (如stackoverflow.com/a/63835684/6309
    • 更糟哈哈,现在我得到bash: git: command not found
    猜你喜欢
    • 2021-02-08
    • 2011-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-05
    • 2010-09-18
    相关资源
    最近更新 更多