I have msysgit set up on my machine and it works perfectly when I’m at home connecting to GitHub. However, when I try to use it from my office, I keep running into this frustrating error:
C:\projects\sample_app>git push --verbose
Pushing to [email protected]:DevUser/TestApp.git
ssh: connect to host github.com port 22: Bad file number
fatal: The remote end hung up unexpectedly
I can successfully clone repositories and pull changes without any issues, but pushing commits back to GitHub always fails with this same error message. I tried switching to HTTPS instead of SSH but that didn’t solve the problem either.
I’m running git version 1.7.3.1.msysgit.0 and this only happens at work, never at home. Has anyone encountered this before and found a solution?
Your office network is blocking SSH connections for Git. I hit this exact problem two years ago when our company updated their firewall. Clone and pull work fine through HTTP, but push operations need different network permissions that corporate firewalls love to block. Here’s what saved me: edit your ~/.ssh/config file and add ‘Host github.com’ with ‘Hostname ssh.github.com’ and ‘Port 443’. This tunnels SSH through the HTTPS port and bypasses most corporate restrictions. If that doesn’t work, generate a personal access token on GitHub and use HTTPS URLs instead of SSH keys. Your IT team won’t open port 22 for security reasons, but these workarounds should get you pushing again.
It seems likely that the issue stems from your workplace’s firewall settings, which may prevent SSH connections on port 22. Corporate networks often implement strict controls on SSH traffic for security reasons, explaining why you’re able to use Git at home without issues. Since switching to HTTPS didn’t resolve the problem, it’s probable that your workplace is also limiting Git functions through deep packet inspection. I’ve experienced similar situations at other workplaces. It would be wise to discuss this with your IT department to see if they can allow access to GitHub or whitelist the necessary ports and domains. Some companies may have specific approval processes for tools like Git, or they might provide internal Git servers or VPN solutions for external access.
That “Bad file number” error usually means network issues, not authentication problems. Your Git version (1.7.3.1) is pretty old - I’d update it first since older msysgit builds had this exact issue a lot. But since it only happens at work, your corporate firewall is probably interfering with SSH connections when you push. In a similar setup, I found configuring Git to use port 443 instead of 22 to be effective by adding this to your SSH config: Host github.com Hostname ssh.github.com Port 443. This allows the connection to pass through the HTTPS port, which corporate firewalls typically don’t block. If that doesn’t solve the issue, you may need to reach out to your IT department to whitelist github.com on port 22 for outbound connections.
check if ur work network blocks outbound connections on port 22. same thing happened to me - IT blocked SSH pushes but not pulls. quick fix: switch to HTTPS with a personal access token instead of SSH keys. worked perfectly.
I dealt with this exact error for weeks at my last job. Turned out our corporate proxy was blocking SSH pushes while allowing clones and pulls - basically read operations worked fine but writes got blocked. I fixed it by setting up Git to use our company proxy explicitly. Try git config --global http.proxy http://proxy-server:port and git config --global https.proxy https://proxy-server:port. You’ll need to ask your network admin for the actual proxy details. Also try switching to GitHub’s HTTPS clone URL with personal access tokens instead of SSH keys - sometimes that bypasses the SSH restrictions completely.