git clone 问题
阅读原文时间:2023年07月09日阅读:1

转自 git clone出现 fatal: unable to access 'https://github.com/…'的解决办法(亲测有效) - 山村码农 - 博客园 (cnblogs.com)

转自:https://blog.csdn.net/dashi\_lu/article/details/89641778

  
如下图所示,当我试图克隆别人的repo时,会发生这样的错误,当我从git:/而不是https:<span class="hljs-comment">//,克隆时,它工作得很好。</span>

&nbsp;发生这种情况是因为代理是在git中配置的。既然它是https代理(而不是http)git <span class="hljs-keyword">config</span> http<span class="hljs-variable">.proxy</span>和git <span class="hljs-keyword">config</span> --<span class="hljs-keyword">global</span> http<span class="hljs-variable">.proxy</span>也无济于事。

解决方案一&nbsp;  
<span class="hljs-number">1</span>、看看你的git配置  
git <span class="hljs-keyword">config</span> --<span class="hljs-keyword">global</span> -l

如果你没有任何与https代理相关的内容,例如https\_proxy = ...问题不在这里。

如果您有与https代理相关的内容,请将其从〜/ <span class="hljs-variable">.gitconfig</span>文件中删除,然后重试。

<span class="hljs-number">2</span>、如果仍然不起作用,请取消设置环境变量&nbsp;  
env|grep -i proxy &nbsp;

&nbsp;你应该有一行或几行https\_proxy = ...

使用以下内容逐个取消设置:取消设置https\_proxy(或HTTPS\_PROXY,具体取决于变量的名称)

<span class="hljs-number">3</span>、再次检查环境变量  
env|grep -i proxy &nbsp;

如果它没有显示任何你应该是好的。

注意:此解决方案可以应用于http和https代理问题。只是变量名称从https更改为http。

&nbsp;解决方案二  
在开启shadowsock的前提下,手动配置git的代理。git客户端输入如下两个命令就可以了。

git <span class="hljs-keyword">config</span> --<span class="hljs-keyword">global</span> http<span class="hljs-variable">.proxy</span> http:<span class="hljs-comment">//127.0.0.1:1080</span>

git <span class="hljs-keyword">config</span> --<span class="hljs-keyword">global</span> https<span class="hljs-variable">.proxy</span> http:<span class="hljs-comment">//127.0.0.1:1080</span>

http:<span class="hljs-comment">//也可以改成sockets5://,但是区别在于:socks5不支持通过pubkey免密登录github,每次提交代码只能输入用户名和密码。http可以支持免密登录。</span>

取消代理:

git <span class="hljs-keyword">config</span> --<span class="hljs-keyword">global</span> --unset http<span class="hljs-variable">.proxy</span>&nbsp;

git <span class="hljs-keyword">config</span> --<span class="hljs-keyword">global</span> --unset https<span class="hljs-variable">.proxy</span>&nbsp;

其实方案一和方案二是同一种方法,不过方案二更加具体一点罢了,大部分问题都可以用方案二解决,当方案二无效时,考虑使用方案一。

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章