Files
wecom-ai-assistant/docs/git-network-troubleshooting.md
bujie9527 df419b499b Add documentation and scripts
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-05 16:44:51 +08:00

226 lines
5.0 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Git 网络连接问题排查指南
## 问题:`fatal: unable to access 'https://github.com/...': Recv failure: Connection was reset`
这是常见的网络连接问题,通常出现在中国大陆访问 GitHub 时。
## 解决方案
### 方案一:配置 Git 代理(推荐)
如果你有可用的代理VPN/SSR/V2Ray可以配置 Git 使用代理:
#### 设置 HTTP/HTTPS 代理
```powershell
# 设置全局代理(所有 Git 操作都使用代理)
git config --global http.proxy http://127.0.0.1:7890
git config --global https.proxy http://127.0.0.1:7890
# 仅针对 GitHub 设置代理
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
# 查看代理配置
git config --global --get http.proxy
git config --global --get https.proxy
```
**常见代理端口**
- Clash: `7890`
- V2Ray: `10808`
- SSR: `1080`
- 其他:根据你的代理软件设置
#### 取消代理设置
```powershell
# 取消全局代理
git config --global --unset http.proxy
git config --global --unset https.proxy
# 取消 GitHub 特定代理
git config --global --unset http.https://github.com.proxy
git config --global --unset https.https://github.com.proxy
```
### 方案二:使用 SSH 代替 HTTPS
SSH 连接通常比 HTTPS 更稳定:
#### 1. 生成 SSH 密钥
```powershell
# 生成 SSH 密钥对
ssh-keygen -t ed25519 -C "your_email@example.com"
# 按 Enter 使用默认路径
# 可以设置密码或直接按 Enter不设置密码
```
#### 2. 添加 SSH 公钥到 GitHub
```powershell
# 查看公钥内容
cat $env:USERPROFILE\.ssh\id_ed25519.pub
# 复制公钥内容,然后:
# 1. 访问 https://github.com/settings/keys
# 2. 点击 "New SSH key"
# 3. 粘贴公钥内容
# 4. 点击 "Add SSH key"
```
#### 3. 测试 SSH 连接
```powershell
# 测试 SSH 连接
ssh -T git@github.com
# 如果看到 "Hi bujie9527! You've successfully authenticated..." 说明成功
```
#### 4. 更改远程仓库 URL 为 SSH
```powershell
# 更改远程 URL 为 SSH
git remote set-url origin git@github.com:bujie9527/wecom-ai-assistant.git
# 验证更改
git remote -v
# 再次推送
git push -u origin main
```
### 方案三:使用 GitHub 镜像(临时方案)
可以使用 GitHub 镜像站点:
```powershell
# 使用镜像站点(不推荐,仅临时使用)
git remote set-url origin https://github.com.cnpmjs.org/bujie9527/wecom-ai-assistant.git
# 推送后改回原地址
git push -u origin main
git remote set-url origin https://github.com/bujie9527/wecom-ai-assistant.git
```
### 方案四:增加超时和重试
```powershell
# 增加 Git 超时时间
git config --global http.postBuffer 524288000
git config --global http.lowSpeedLimit 0
git config --global http.lowSpeedTime 999999
# 使用重试机制推送
git push -u origin main --verbose
```
### 方案五:使用 GitHub CLIgh
如果安装了 GitHub CLI
```powershell
# 安装 GitHub CLI如果还没有
# 下载https://cli.github.com/
# 登录
gh auth login
# 推送代码
git push -u origin main
```
## 快速诊断
### 检查网络连接
```powershell
# 测试 GitHub 连接
Test-NetConnection github.com -Port 443
# 测试 DNS 解析
nslookup github.com
# 使用 curl 测试
curl -I https://github.com
```
### 检查 Git 配置
```powershell
# 查看所有 Git 配置
git config --list
# 查看远程仓库配置
git remote -v
# 查看当前分支
git branch
```
## 推荐方案
**最佳实践**(按优先级):
1. **配置代理**(如果你有 VPN/代理)
```powershell
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
```
2. **使用 SSH**(更稳定,一次配置长期使用)
```powershell
# 生成 SSH 密钥并添加到 GitHub
# 然后更改远程 URL
git remote set-url origin git@github.com:bujie9527/wecom-ai-assistant.git
```
3. **重试推送**(网络临时问题时)
```powershell
git push -u origin main
```
## 常见错误和解决方案
### 错误 1`SSL certificate problem`
```powershell
# 临时忽略 SSL 验证(不推荐,仅测试用)
git config --global http.sslVerify false
```
### 错误 2`Authentication failed`
```powershell
# 清除缓存的凭据
git credential-manager-core erase
# 或
git credential reject https://github.com
# 重新推送时会提示输入用户名和 token
```
### 错误 3`Connection timed out`
- 检查防火墙设置
- 检查代理配置
- 尝试使用 SSH
## 验证推送成功
推送成功后,访问以下 URL 验证:
- **仓库地址**https://github.com/bujie9527/wecom-ai-assistant
- **提交历史**https://github.com/bujie9527/wecom-ai-assistant/commits/main
## 获取帮助
如果以上方案都无法解决:
1. 检查 GitHub 状态https://www.githubstatus.com/
2. 查看 Git 日志:`git push -u origin main --verbose`
3. 提交 Issuehttps://github.com/bujie9527/wecom-ai-assistant/issues