← 返回首页

GitHub 连接超时

推送到 GitHub 时出现 connection timeout 错误

❌ 错误信息
fatal: unable to access 'https://github.com/username/repo.git/': 
Failed to connect to github.com port 443 after 21066 ms: Could not connect to server

# 或
fatal: cannot exec 'git-remote-https': No such file or directory

原因分析

解决方案

方案一:检查并关闭代理

✅ 推荐

如果你开了代理/VPN,尝试关闭或配置正确的代理端口

# 检查 Git 代理设置
git config --global --get http.proxy
git config --global --get https.proxy

# 清除代理设置
git config --global --unset http.proxy
git config --global --unset https.proxy

方案二:配置代理

如果你需要代理才能访问 GitHub:

# 配置 HTTP 代理(假设代理端口是 7890)
git config --global http.proxy http://127.0.0.1:7890
git config --global https.proxy http://127.0.0.1:7890

# 或者使用 SOCKS5 代理
git config --global http.proxy socks5://127.0.0.1:7890
git config --global https.proxy socks5://127.0.0.1:7890

方案三:手动网页上传

如果以上方案都无法解决:

  1. 打开 GitHub 仓库页面
  2. 点击 Add fileUpload files
  3. 直接拖拽文件或粘贴代码
  4. 点击 Commit changes

方案四:使用 GitHub CLI

# 安装 GitHub CLI
# Windows: winget install GitHub.cli
# macOS: brew install gh

# 登录
gh auth login

# 推送代码
gh repo sync

检测网络

# 测试 GitHub 连接
curl -I https://github.com

# 测试特定端口
telnet github.com 443

常见问题

Q: 代理设置后还是连不上?

检查代理是否正常工作,尝试用浏览器访问 github.com

Q: 错误 "Permission denied"?

这可能是 SSH 密钥问题,尝试使用 HTTPS 方式:

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