Github推送超时问题解决
在 Git 中设置网络代理可以解决因网络限制导致的连接超时或推送失败问题。以下是 **HTTP/HTTPS 代理** 和 **SSH 代理** 的设置方法:
---
## **1. 设置 HTTP/HTTPS 代理(适用于 ` https://github.com ` 克隆的仓库)**
如果你的 Git 远程地址是 ` https://github.com/...` ,可以通过以下命令设置代理:
### **(1) 设置全局代理**
```bash
# 设置 HTTP 代理(如 Clash等默认端口)
git config --global http.proxy http://127.0.0.1:7890
# 设置 HTTPS 代理
git config --global https.proxy http://127.0.0.1:7890
```
- `7890` 是常见代理端口(Clash 默认),请根据你的代理工具调整。
### **(2) 仅对 GitHub 设置代理**
```bash
git config --global http. https://github.com.proxy http://127.0.0.1:7890
git config --global https. https://github.com.proxy http://127.0.0.1:7890
```
### **(3) 取消代理**
```bash
git config --global --unset http.proxy
git config --global --unset https.proxy
```
---
## **2. 设置 SSH 代理(适用于 `git@github.com` 克隆的仓库)**
如果你的 Git 远程地址是 `git@github.com:...`,需要配置 SSH 走代理:
### **(1) 修改 SSH 配置文件**
打开 `~/.ssh/config`(Linux/macOS)或 `C:\Users\<用户名>\.ssh\config`(Windows),添加:
```config
Host github.com
User git
Hostname github.com
ProxyCommand nc -X 5 -x 127.0.0.1:7890 %h %p
```
- `-X 5` 表示 SOCKS5 代理(如果是 HTTP 代理,用 `-X connect`)。
- `7890` 是代理端口,请根据实际情况修改。
### **(2) 测试 SSH 连接**
```bash
ssh -T git@github.com
```
如果返回 `You've successfully authenticated`,说明代理生效。
---
## **3. 检查代理是否生效**
```bash
git config --global --get http.proxy # 查看 HTTP 代理
git config --global --get https.proxy # 查看 HTTPS 代理
```
---
## **4. 其他常见问题**
### **(1) 代理端口错误**
- 确保代理工具(Clash)正在运行,且端口正确。
- Windows 用户可尝试 `netsh winhttp show proxy` 查看系统代理。
### **(2) 公司/校园网限制**
- 尝试切换网络(如手机热点)。
- 使用 **SSH + 代理** 代替 HTTPS。
### **(3) 关闭 Git SSL 验证(不推荐,仅临时解决)**
```bash
git config --global http.sslVerify false
```
---
## **总结**
| 代理类型 | 适用场景 | 设置方法 |
|----------------|----------------------------|------------------------------------------|
| **HTTP/HTTPS** | ` https://github.com ` 仓库 | `git config --global http.proxy ...` |
| **SSH** | `git@github.com` 仓库 | 修改 `~/.ssh/config` 文件 |
如果仍有问题,请提供具体的错误信息(如 `Failed to connect to github.com port 443: Timed out`)。
如果仍有问题,请提供具体的错误信息(如 `Failed to connect to github.com port 443: Timed out`)。

浙公网安备 33010602011771号