Git致命错误:协议“https”不受支持。

536

我正在阅读Github的分叉指南:https://guides.github.com/activities/forking/, 我正在尝试将存储库克隆到我的电脑上。但是,运行以下命令:

$ git clone https://github.com/./Spoon-Knife.git
Cloning into 'Spoon-Knife'...
fatal: protocol 'https' is not supported

也尝试使用SSH:

$ git clone git@github.com:./Spoon-Knife.git
Cloning into 'Spoon-Knife'...
Warning: Permanently added the RSA host key for IP address '.' to the list of known hosts.
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

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

我需要更改电脑上的一些配置设置吗,还是这是 GitHub 的问题?

编辑:我已将我的用户名和 IP 地址替换为“。”


3
请检查复制的文本中是否存在任何奇怪的特殊字符。可以尝试手动输入整个网址,而不是从Github复制。也可以确认一下github.com是否确实解析到Github,或者是否有其他服务器将其重定向。 - lw1.at
1
或许是你电脑上的其他软件损坏了已安装的git(参见https://dev59.com/yWUp5IYBdhLWcg3wEEM6)。在这种情况下,重新安装可能会解决问题。 - lw1.at
1
如果您正在使用GitHub桌面版或任何其他GUI Git软件,请确保仅复制并粘贴URL,而不包括开头的git clone。 - Aarony
25个回答

1569

问题可能出在这里。

你尝试使用

  • CTRL + V

进行粘贴,但之前没有成功,所以你用了经典的

  • 右键单击 - 粘贴**。

不幸的是,每当你在终端上按CTRL + V时,它都会添加一个隐藏的 ^?字符

  • (至少在我的机器上,它被编码成这样)。

只有在你按下退格键后才会出现这个字符

  • backspace

(请在git bash上尝试一下)。

因此,你的链接变成了^?https://...

这是无效的。


21
为什么会发生这种情况? - champion-runner
5
好的,谢谢!我使用鼠标右键将其粘贴。然后,我将光标放在“https”的中间,并多次按下退格键。 - Liker777
2
如果您正在使用GitHub桌面版或任何其他GUI Git软件,请确保仅复制并粘贴URL,而不要在开头添加git clone。 - Aarony
1
在使用Source Tree将AWS Code Commit Repo附加到我的本地项目时,遇到了完全相同的问题。虽然这个答案已经很老了,但它仍然节省了我很多时间。 - Nantoka
1
在Git Bash中,按下Ctrl + Ins可以复制,按下Shift + Ins可以粘贴。 - Nathaniel Jones
显示剩余4条评论

38

编辑:这位用户的问题通过启动一个新的终端会话得到解决。

协议(https)之前的?不被支持。您需要这个:

git clone git@github.com:octocat/Spoon-Knife.git

或者这个:

git clone https://github.com/octocat/Spoon-Knife.git

选择要克隆的位置


我也尝试使用SSH,但它没有起作用。我的用户名处有一个“.”。 - Hank Lin
你是否已经fork了这个项目?你把它设置为公开的还是私有的?如果是公开的,你应该能够从上面显示的框中复制URL。如果它是私有的,你必须将你的私钥添加到你的账户中。 - TomDunning
2
谢谢 - 我重新启动了命令行,不知何故现在它可以工作了。我仍然很困惑为什么一开始它不能工作。 - Hank Lin
1
我也解决了在新命令行中打开问题。我在安装 Git 时选中了打开 Git Bash 的选项,并使用它进行了首次 git 克隆操作。那可能是原因。 - Detached Laconian
2
重启我的终端解决了这个问题。 - Elkas
显示剩余3条评论

23

简单的答案就是删除 https:

您的 Repo. : (git clone https://........)

就像这样 (git clone ://.......)

然后再输入 (git clone https://........)


17

只需在URL中使用双引号,例如:git clone "https://yourRepoUrl"

某种程度上看起来好像是在开头使用了2个引号,不知道为什么。

我也遇到了相同的错误 => fatal: protocol ''https' is not supported(可以看到 https 上有2个引号)。


在所有其他解决方案中...这是最简单和最直观的解决方案!谢谢!! - Sayed Sadat

11
如果您使用Visual Studio或Git GUI进行克隆,您需要删除“git clone”命令。 只需要输入地址即可。

8

有些可疑的事情正在发生。可能是一个不一致的github bug(A/B测试?)

我在使用Windows10和Firefox,刚刚复制了一个checkout URL,结果多了一个字符。但只有第一次出现,第二次就没有了。我不得不查看我的历史记录才看到它!

这是我的历史记录:

git clone --recursive https://github.com/amzeratul/halley-template
git clone --recursive http://github.com/amzeratul/halley-template
git clone --recursive github.com/amzeratul/halley-template
git clone --recursive https://github.com/amzeratul/halley-template

历史命令不会显示额外的字符。就像我在复制粘贴到终端时没有渲染它一样。你可以看到我试图删除“s”和整个协议吗?当退格键移动了比我预期少一个字符时,我才被激发进一步探究!

我将我的shell历史文件保存到一个带有十六进制编辑器的机器上并进行了以下操作:

00000000  xx xx xx xx xx xx xx 0a  67 69 74 20 63 6c 6f 6e  |xxxxxxx.git clon|
00000010  65 20 2d 2d 72 65 63 75  72 73 69 76 65 20 c2 96  |e --recursive ..|
00000020  68 74 74 70 73 3a 2f 2f  67 69 74 68 75 62 2e 63  |https://github.c|
00000030  6f 6d 2f 61 6d 7a 65 72  61 74 75 6c 2f 68 61 6c  |om/amzeratul/hal|
00000040  6c 65 79 2d 74 65 6d 70  6c 61 74 65 0a 67 69 74  |ley-template.git|
00000050  20 2d 2d 68 65 6c 70 0a  67 69 74 20 75 70 64 61  | --help.git upda|
00000060  74 65 2d 67 69 74 2d 66  6f 72 2d 77 69 6e 64 6f  |te-git-for-windo|
00000070  77 73 0a 67 69 74 20 63  6c 6f 6e 65 20 2d 2d 72  |ws.git clone --r|
00000080  65 63 75 72 73 69 76 65  20 c2 96 68 74 74 70 73  |ecursive ..https|
00000090  3a 2f 2f 67 69 74 68 75  62 2e 63 6f 6d 2f 61 6d  |://github.com/am|
000000a0  7a 65 72 61 74 75 6c 2f  68 61 6c 6c 65 79 2d 74  |zeratul/halley-t|
000000b0  65 6d 70 6c 61 74 65 0a  63 75 72 6c 20 2d 2d 76  |emplate.curl --v|
000000c0  65 72 73 69 6f 6e 0a 63  64 20 63 6f 64 65 0a 67  |ersion.cd code.g|
000000d0  69 74 20 63 6c 6f 6e 65  20 2d 2d 72 65 63 75 72  |it clone --recur|
000000e0  73 69 76 65 20 c2 96 68  74 74 70 73 3a 2f 2f 67  |sive ..https://g|
000000f0  69 74 68 75 62 2e 63 6f  6d 2f 61 6d 7a 65 72 61  |ithub.com/amzera|
00000100  74 75 6c 2f 68 61 6c 6c  65 79 2d 74 65 6d 70 6c  |tul/halley-templ|
00000110  61 74 65 0a 67 69 74 20  63 6c 6f 6e 65 20 2d 2d  |ate.git clone --|
00000120  72 65 63 75 72 73 69 76  65 20 c2 96 68 74 74 70  |recursive ..http|
00000130  3a 2f 2f 67 69 74 68 75  62 2e 63 6f 6d 2f 61 6d  |://github.com/am|
00000140  7a 65 72 61 74 75 6c 2f  68 61 6c 6c 65 79 2d 74  |zeratul/halley-t|
00000150  65 6d 70 6c 61 74 65 0a  67 69 74 20 63 6c 6f 6e  |emplate.git clon|
00000160  65 20 2d 2d 72 65 63 75  72 73 69 76 65 20 67 69  |e --recursive gi|
00000170  74 68 75 62 2e 63 6f 6d  2f 61 6d 7a 65 72 61 74  |thub.com/amzerat|
00000180  75 6c 2f 68 61 6c 6c 65  79 2d 74 65 6d 70 6c 61  |ul/halley-templa|
00000190  74 65 0a 67 69 74 20 63  6c 6f 6e 65 20 2d 2d 72  |te.git clone --r|
000001a0  65 63 75 72 73 69 76 65  20 68 74 74 70 73 3a 2f  |ecursive https:/|
000001b0  2f 67 69 74 68 75 62 2e  63 6f 6d 2f 61 6d 7a 65  |/github.com/amze|
000001c0  72 61 74 75 6c 2f 68 61  6c 6c 65 79 2d 74 65 6d  |ratul/halley-tem|
000001d0  70 6c 61 74 65 0a                                 |plate.|
000001d6

在URL之前插入了一个字符。不清楚它是什么。它不是扩展ASCII码(在那种情况下它应该是<Â->),并且当我把它粘贴到几乎所有地方时,它被隐藏了。这个十六进制值最接近的可能是https://www.fileformat.info/info/unicode/char/c298/index.htm,但我没有看到任何UTF前缀(可能已经丢失)。
这一切可能会误导,因为我丢失了页面/剪贴板,并且只从保存的shell历史记录文件中工作,这可能非常容易丢失原始错误/恶意注入的数据。

我可以确认这与我遇到的情况类似,在Windows上将内容粘贴到gitbash时会添加一些奇怪的字符(看不见的字符)。 - Arruda

6

从普通记事本中复制:

git clone https://github.com/./Spoon-Knife.git

然后将其粘贴到命令提示符中。


3

如果你正在使用Git Bash:

不要通过按下Ctrl + V来粘贴链接。
你可以直接输入git clone,然后右键单击粘贴


3
我遇到了一个错误,看起来与这个非常相似,因为我在URL周围放置了单引号:
致命错误:协议 "https" 不受支持。
从URL中删除单引号即可解决问题。

这帮助我解决了问题。谢谢。 - SimpleUser

3

问题

git clone https://github.com/rojarfast1991/TestGit.git fatal: protocol 'https' is not supported

解决方法:

步骤:

(1):打开新的终端并克隆 git 仓库。

git clone https://github.com/rojarfast1991/TestGit.git

(2):自动 git 登录提示将会弹出,并要求输入用户凭证。

用户名:xxxxxxx

密码:xxxxxxx

最后,克隆将会开始...

git clone https://github.com/rojarfast1991/TestGit.git
Cloning into 'TestGit'...
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (4/4), done.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接