git push/pull 超时

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/757432/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 06:20:34  来源:igfitidea点击:

git push/pull times out

gittimeoutfirewall

提问by Gabe Moothart

I can't git push/pull to github from my corporate vpn:

我无法从我的公司 vpn git push/pull 到 github:

git push origin master
ssh: connect to host github.com port 22: Connection timed out
fatal: The remote end hung up unexpectedly

I assume this is a firewall issue, b/c if I disconnect from the vpn it works. Is there anything I can do to work around it? Or am I stuck disconnecting from the vpn when I need to push/pull?

我认为这是一个防火墙问题,如果我断开与它工作的 vpn 的连接,则 b/c。我能做些什么来解决它吗?或者当我需要推/拉时,我是否无法与 vpn 断开连接?

采纳答案by araqnid

Not sure which type of VPN you're using, but this sort of effect is usually due to the VPN setup routing all your traffic over the VPN. You can work around that by updating your routing tables to route traffic to github back over your Ethernet (I assume) interface rather than over the VPN.

不确定您使用的是哪种类型的 VPN,但这种影响通常是由于 VPN 设置通过 VPN 路由您的所有流量。您可以通过更新路由表以通过以太网(我假设)接口而不是通过 VPN 将流量路由回 github 来解决这个问题。

For example route add 65.74.177.129 eth0will route traffic to github over eth0. This is the Linux syntax; Windows has a "route" command as well that is broadly similar.

例如,route add 65.74.177.129 eth0将通过 eth0 将流量路由到 github。这是 Linux 语法;Windows 也有一个大致相似的“路由”命令。

(This isn't really a git-specific problem, and in fact you should be able to demonstrate the problem by trying to connect to github.com port 22 with any client such as telnet, nc or PuTTY: sshd will usually print a banner with its version number as soon as you connect)

(这并不是一个真正的 git 特定问题,事实上,您应该能够通过尝试使用任何客户端(如 telnet、nc 或 PuTTY)连接到 github.com 端口 22 来证明该问题:sshd 通常会打印一个横幅连接后立即使用其版本号)

回答by trnqllt

I had exactly the same problem and adding a route for github solved my issues as well.

我遇到了完全相同的问题,为 github 添加路由也解决了我的问题。

The command for windows (or cygwin in my case) would be: route add <ip> <gateway>. So what solved it for me was simply: route add 207.97.227.239 192.168.0.1.

windows(或在我的情况下为 cygwin)的命令是:route add <ip> <gateway>. 所以为我解决的问题很简单:route add 207.97.227.239 192.168.0.1.

Please note the different IP for github.com I used in comparison with the one araqnid had, two years ago. :)

请注意我使用的 github.com 与两年前 araqnid 使用的 IP 不同。:)

If you are not sure whether your added route still works after some time, just type (on windows or cygwin) tracert github.comto see where the packets get routed. If the first hit seems to be located within your company, the route you added is not valid anymore and you would need to add a new route.

如果您不确定您添加的路由在一段时间后是否仍然有效,只需键入(在 windows 或 cygwin 上)tracert github.com以查看数据包的路由位置。如果第一个命中似乎位于您的公司内,则您添加的路线不再有效,您需要添加新路线。

回答by Kyle Clegg

Mac users:This occurred for me immediately after installing an updated version of OS X. Before you dig too deep into changing network settings I suggest doing an extra restart. This corrected the issue for me.

Mac 用户:我在安装更新版本的 OS X 后立即发生了这种情况。在您深入研究更改网络设置之前,我建议您额外重新启动。这为我纠正了这个问题。

回答by Jonathan L

Increase the ssh connection timeout in your machine.

增加机器中的 ssh 连接超时。

Create ~/.ssh/config file (if it doesn't exist).

创建 ~/.ssh/config 文件(如果它不存在)。

Add SSH ServerAliveInterval ServerAliveCountMax settings into the file, eg:

将 SSH ServerAliveInterval ServerAliveCountMax 设置添加到文件中,例如:

Host *
     ServerAliveInterval 86400
     ServerAliveCountMax 4

Tested on Ubuntu 18.04.4 LTS through vpn.

通过 vpn 在 Ubuntu 18.04.4 LTS 上测试。

See more at here

此处查看更多信息