I have a project where every time I git push to my GitHub account using SSH keys (on Windows), the command line hangs for several minutes, and then I eventually get the error Connection to github.com closed by remote host. I can do git pull or git fetch successfully. I can also do ssh -T [email protected] successfully.
I've been pushing successfully to this project for a while. I think this problem started when I switched to use OpenSSH as my SSH agent and configured it to use two different keys for different SSH accounts. However, I've disabled the separate keys (I renamed my .ssh\config file) to test, and I still have the same problem.
I tried cloning this project to another location on my computer, updating it, and doing a git push and that works correctly from the newly cloned repository.
Here are the results of git remote show origin from my original repo.
* remote origin
Fetch URL: [email protected]:MyUserName/MyRepo.git
Push URL: [email protected]:MyUserName/MyRepo.git
HEAD branch: master
Remote branches:
develop tracked
master tracked
test new (next fetch will store in remotes/origin)
Local branches configured for 'git pull':
develop merges with remote develop
master merges with remote master
Local refs configured for 'git push':
develop pushes to develop (fast-forwardable)
master pushes to master (fast-forwardable)
Here are the results of git remote show origin from my newly cloned repo. Note that the test branch is a new branch that I created so I didn't overwrite master.
* remote origin
Fetch URL: [email protected]:MyUserName/MyRepo.git
Push URL: [email protected]:MyUserName/MyRepo.git
HEAD branch: master
Remote branches:
develop tracked
master tracked
test tracked
Local branches configured for 'git pull':
master merges with remote master
test merges with remote test
Local refs configured for 'git push':
master pushes to master (up to date)
test pushes to test (up to date)
I can't explain the long hang time, but the eventual Connection to github.com closed by remote host. message is likely caused by your SSH connection with GitHub timing out. I recently helped a coworker solve a similar issue where our Husky pre-push hook was taking a long time to complete on her machine. By the time the hook finished, she received the same Connection to github.com closed by remote host. message.
We found the solution was keeping her connection alive by setting values for ServerAliveInterval and ServerAliveCountMax in her .ssh\config file. For example, adding the following settings would send a null packet to the server every 60 seconds (keeping the connection alive) for 30 rounds. This would buy you 30 minutes of connection.
Host *
ServerAliveInterval 60
ServerAliveCountMax 30
You can adjust the the values however you see fit for your use.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With