首页 > 解决方案 > 带有 ssh 地址的 Git 克隆失败

问题描述

我想使用命令从 Github 克隆一个 git repo

git clone git@github.com:rgov/Thunderbolt3Unblocker.git

但我明白了

Cloning into 'Thunderbolt3Unblocker'...
fatal: unable to access 'https://github.com:rgov/Thunderbolt3Unblocker.git/': Port number ended with 'r'

似乎 git 将用户名“rgov”解释为端口号?

git版本是2.27.0

标签: git

解决方案


检查git config --global -l任何 insteadOf 指令的输出,例如:

git config --global url."https://github.com".insteadOf git@github.com

这可以解释为什么被https://github.comgit@github.com取代了

请注意,这个指令写得不好:它应该是:

git config --global url."https://github.com/".insteadOf git@github.com:
                                          ^^^                        ^^^

这至少会给你一个有效的 HTTPS URL:

https://github.com/rgov/Thunderbolt3Unblocker.git
                 ^^^

但是,如果您想使用 SSH,insteadOf请从您的全局 git 配置中删除该指令。

git config --global --unset-all url."https:github.com".insteadof

推荐阅读