Gabe Moothart
Gabe Moothart

Reputation: 32112

git push/pull times out

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

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?

Upvotes: 26

Views: 50272

Answers (5)

Robert
Robert

Reputation: 8663

I see this happening with github.com repositories that use git:// URLs like git://github.com/pre-commit/pre-commit-hooks. Switching them to git+ssh:// fixed it for me; for example, the above URL becomes git+ssh://[email protected]/pre-commit/pre-commit-hooks.

This may require you to set up ssh keys in github first.

If you don't want to manually change all your URLs, you can configure git to swap them:

git config --global url."[email protected]:".insteadOf "git://github.com/"

Upvotes: 0

Jonathan L
Jonathan L

Reputation: 10688

Increase the ssh connection timeout in your machine.

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

Add SSH ServerAliveInterval ServerAliveCountMax settings into the file, eg:

Host *
     ServerAliveInterval 86400
     ServerAliveCountMax 4

Tested on Ubuntu 18.04.4 LTS through vpn.

See more at here

Upvotes: 2

Kyle Clegg
Kyle Clegg

Reputation: 39470

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.

Upvotes: 3

trnqllt
trnqllt

Reputation: 41

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

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.

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

If you are not sure whether your added route still works after some time, just type (on windows or cygwin) tracert github.com to 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.

Upvotes: 4

araqnid
araqnid

Reputation: 133692

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.

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

(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)

Upvotes: 16

Related Questions