# Git仓库经常推送失败，不是这个报错就是那个报错，但肯定是网络环境的问题，求佬友解答

**URL:** <https://linux.do/t/topic/246259>\
**Category:** 开发调优\
**Tags:** 计算机网络\
**Created:** [2024 年10 月 30 日 12:06 UTC](https://linux.do/t/topic/246259 "2024-10-30T12:06:42Z")\
**Posts on this page:** 13\
**Page:** 2

<div class="post-metadata">

作者： ![heart](https://cdn.ldstatic.com/user_avatar/linux.do/heart/32/9586_2.png) [@heart](https://linux.do/u/heart)\
发布日期： [2024 年10 月 31 日 01:52 UTC](https://linux.do/t/topic/246259/24 "2024-10-31T01:52:14Z")

</div>

我公司的仓库是放在github上的，之前也经常推不上去，然后搜了各种教程，我用的是clash for windows  
解决方案如下：  
1 取消git代理  
git config --global --unset http.proxy  
git config --global --unset https.proxy

2 设置自己的  
git config --global http.proxy [http://127.0.0.1](http://127.0.0.1):xxxx  
git config --global https.proxy [http://127.0.0.1](http://127.0.0.1):xxxx  
xxxx是软件中的端口

 ![image](https://cdn3.ldstatic.com/original/3X/e/e/eeaa345d5eb7701d69161400b2ffeb9e2177a3c9.png)  
希望能帮到你

---

<div class="post-metadata">

作者： ![gamecrafters](https://cdn.ldstatic.com/user_avatar/linux.do/gamecrafters/32/117097_2.png) [@gamecrafters](https://linux.do/u/gamecrafters)\
发布日期： [2024 年10 月 31 日 02:02 UTC](https://linux.do/t/topic/246259/25 "2024-10-31T02:02:57Z")

</div>

你梯子除非开tun，不然你shell的请求一定是不过你的分流规则的

---

<div class="post-metadata">

作者： ![alertsc](https://cdn.ldstatic.com/user_avatar/linux.do/alertsc/32/38950_2.png) [@alertsc](https://linux.do/u/alertsc)\
发布日期： [2024 年10 月 31 日 02:04 UTC](https://linux.do/t/topic/246259/26 "2024-10-31T02:04:37Z")

</div>

我也常被这个问题困扰。学习了。

---

<div class="post-metadata">

作者： ![alertsc](https://cdn.ldstatic.com/user_avatar/linux.do/alertsc/32/38950_2.png) [@alertsc](https://linux.do/u/alertsc)\
发布日期： [2024 年10 月 31 日 02:12 UTC](https://linux.do/t/topic/246259/27 "2024-10-31T02:12:30Z")

</div>

C:\Users\我的用户名 目录下没有.ssh目录。但alluser下有个ssh目录。另外config是建一个无后缀的文本文件吗？

---

<div class="post-metadata">

作者： ![alertsc](https://cdn.ldstatic.com/user_avatar/linux.do/alertsc/32/38950_2.png) [@alertsc](https://linux.do/u/alertsc)\
发布日期： [2024 年10 月 31 日 02:14 UTC](https://linux.do/t/topic/246259/28 "2024-10-31T02:14:11Z")

</div>

让git走SSH具体是如何配置？C:\Users\我的用户名 目录下没有.ssh目录。但alluser下有个ssh目录。另外config是建一个无后缀的文本文件吗？用v2rayng也可以吧。

---

<div class="post-metadata">

作者： ![layden](https://cdn.ldstatic.com/user_avatar/linux.do/layden/32/305757_2.png) [@layden](https://linux.do/u/layden)\
发布日期： [2024 年10 月 31 日 03:24 UTC](https://linux.do/t/topic/246259/29 "2024-10-31T03:24:27Z")

</div>

终端键入 ssh-keygen 一直回车会帮你建立 ~/.ssh 目录同时创建公钥和私钥，公钥（\*.pub）需要自行配置到 Github 上。

新增 ~/.ssh/config 文件（无后缀）：

```plaintext
Host github.com
	HostName %h
	Port 22
	IdentityFile ~/.ssh/id_rsa
	# ProxyCommand e:/git/mingw64/bin/connect -S 127.0.0.1:7897 %h %p

```

其中 ProxyCommand 是代理配置，支持注释。

这样就完成 [github.com](http://github.com) 和私钥之间的关联，后续使用 SSH 连接 [github.com](http://github.com) 会自动使用配置的私钥（IdentityFile）进行验证。

---

<div class="post-metadata">

作者： ![alertsc](https://cdn.ldstatic.com/user_avatar/linux.do/alertsc/32/38950_2.png) [@alertsc](https://linux.do/u/alertsc)\
发布日期： [2024 年10 月 31 日 03:55 UTC](https://linux.do/t/topic/246259/30 "2024-10-31T03:55:47Z")

</div>

谢谢。我看了很多相关文章都没提到config文件的配置。是必须配置的吗？走22端口和443端口各有什么优劣。ProxyCommand也不太理解，是如果配置了会后台启动proxy？必须要配置吗？

---

<div class="post-metadata">

作者： ![alertsc](https://cdn.ldstatic.com/user_avatar/linux.do/alertsc/32/38950_2.png) [@alertsc](https://linux.do/u/alertsc)\
发布日期： [2024 年10 月 31 日 03:58 UTC](https://linux.do/t/topic/246259/31 "2024-10-31T03:58:21Z")

</div>

找到一篇描述如何通过SSH走HTTPS代理提交的文章。涉及各种方案。学习一下。[adangel.org - Using github ssh behind http proxy](https://adangel.org/2020/10/15/github-behind-proxy/#:~:text=To%20workaround%20the%20firewall%2C%20github%20provides%20SSH%20access,of%20github.com%3A%20Host%20github.com%20Hostname%20ssh.github.com%20Port%20443)

---

<div class="post-metadata">

作者： ![layden](https://cdn.ldstatic.com/user_avatar/linux.do/layden/32/305757_2.png) [@layden](https://linux.do/u/layden)\
发布日期： [2024 年10 月 31 日 04:38 UTC](https://linux.do/t/topic/246259/32 "2024-10-31T04:38:33Z")

</div>

方法有很多，不添加 config 还可以用 ssh-agent 管理私钥，但 Windows 下这是个服务，需要启用才行。

config 最大的作用是让 Host 和 IdentityFile 关联，配置 Port 不是因为端口由 config 说了算的意思。像 GitHub 这种提供了 [github.com:22](http://github.com:22) 和 [ssh.github.com:443](http://ssh.github.com:443) 两种连接，config 配置 Port 的话，可以在建立 SSH 连接的时候省略掉端口的书写。

SSH 不能直接使用代理，需要借助其他工具来帮助和代理建立连接，ProxyCommand 中配置了 connect.exe 就是帮助建立连接的工具。

建议先了解一下 OpenSSH 的知识，弄懂这个你就知道怎么建立 SSH 连接了，这本身就是 Git 使用了 OpenSSH 的技术，和 Git 没什么关系。

---

<div class="post-metadata">

作者： ![Cloud-009](https://cdn.ldstatic.com/user_avatar/linux.do/cloud-009/32/1440181_2.png) [@Cloud-009](https://linux.do/u/Cloud-009)\
发布日期： [2024 年10 月 31 日 05:27 UTC](https://linux.do/t/topic/246259/33 "2024-10-31T05:27:25Z")

</div>

对，你这样应该没问题，我之前把端口号设置成了别的，而不是代理软件的，所以就报错了 😇

---

<div class="post-metadata">

作者： ![zen67060](https://cdn.ldstatic.com/user_avatar/linux.do/zen67060/32/539666_2.png) [@zen67060](https://linux.do/u/zen67060)\
发布日期： [2024 年10 月 31 日 06:02 UTC](https://linux.do/t/topic/246259/34 "2024-10-31T06:02:54Z")

</div>

csdn上都是一些无脑复制的错误答案

你要是想给 git:// 形式的仓库走代理

就看他这个 [Git仓库经常推送失败，不是这个报错就是那个报错，但肯定是网络环境的问题，求佬友解答 - #29，来自 layden](https://linux.do/t/topic/246259/29)

---

<div class="post-metadata">

作者： ![alertsc](https://cdn.ldstatic.com/user_avatar/linux.do/alertsc/32/38950_2.png) [@alertsc](https://linux.do/u/alertsc)\
发布日期： [2024 年10 月 31 日 06:17 UTC](https://linux.do/t/topic/246259/35 "2024-10-31T06:17:08Z")

</div>

感谢。我没有配置代理。但测试22端口和指定443端口都成功连接。考虑到是为了解决连接不畅问题。config里指定22还是443端口更好？我修改了hosts文件来解决域名连接问题。

---

<div class="post-metadata">

作者： ![XiaoHuang](https://cdn.ldstatic.com/user_avatar/linux.do/xiaohuang/32/338864_2.png) [@XiaoHuang](https://linux.do/u/XiaoHuang)\
发布日期： [2024 年10 月 31 日 08:00 UTC](https://linux.do/t/topic/246259/36 "2024-10-31T08:00:14Z")

</div>

我设置的代理，按佬友们说的整上代理就行

[上一页](https://linux.do/t/topic/246259.md?page=1)
