问题

git报错:Failed to connect to github.com port 443: Connection refused

解决

1. 检查网络

确保网络连接正常,可以访问github.com。

2. 检查git配置

使用以下命令检查git配置:

1
git config --global --list

如果配置中包含http.proxyhttps.proxy,则删除它们:

1
2
git config --global --unset http.proxy
git config --global --unset https.proxy

3. 检查防火墙

确保防火墙没有阻止git的443端口。

4. 检查代理

确保没有设置代理,可以使用以下命令检查代理:

1
curl -I https://github.com

如果返回的HTTP/1.1 200 OK,则表示没有设置代理。如果设置了代理,在windows上可以在设置中关闭代理,在linux上可以使用以下命令关闭代理:

1
2
unset http_proxy
unset https_proxy

5. 检查git版本

确保git版本在2.0以上,可以使用以下命令检查git版本:

1
git --version

如果版本低于2.0,则需要升级git。

6. 检查DNS

如果以上方法都没有解决问题,可以尝试更换DNS,例如使用Google DNS(8.8.8.8和8.8.4.4)。

7. 检查证书

如果以上方法都没有解决问题,可以尝试更换证书,例如使用Let’s Encrypt证书。

8. 检查SSH

如果以上方法都没有解决问题,可以尝试使用SSH方式推送代码,例如:

1
git remote set-url origin git@github.com:username/repo.git

然后使用以下命令推送代码:

1
git push origin master