vscode推送项目到github,本地仓库和远程仓库已经绑定,最后一步推送始终报错怎么解决。
-
知其然:代理 + HTTPS = 必 403,SSH + 密钥 = 一劳永逸
-
知其所以然:共享代理 IP 被 GitHub 风控封禁,SSH 走 22 端口 + 密钥配对,彻底绕过 IP 检测
-
适用人群:野生程序员、非专业开发者、被墙折磨的散修

问题复盘:
我正在做一个 AI 合同生成系统 (暂命名为"合同时空"),代码写在本地 E:\AIGC_design\hetong,用 VS Code 开发。 作为一个 野生程序员,没团队、没框架、没规范,纯靠热情和自学。
今天想把项目推到 GitHub 上,仓库已建好:https://github.com/xxx/hetong_20251027.git。
第一次尝试:VS Code 一键 Publish → 直接报错
Git: fatal: unable to access 'https://...': Failed to connect to 127.0.0.1 port 10090...
→ 我以为:网络问题,代理没开。
第二次尝试:配置代理(第三方"表格云"工具)
-
打开代理软件,发现 HTTP 代理端口是 10090(不是常见 7890)
-
在 VS Code 终端执行:
git config --global http.proxy http://127.0.0.1:10090
git config --global https.proxy http://127.0.0.1:10090
→ 测试 curl -x http://127.0.0.1:10090 https://api.github.com
→ 超时,连不上
→ 我以为:端口错了,或者代理没开 LAN。

第四次尝试:切换到 Grok(xAI 的 AI)
Grok 说:
"你代理能上网,但 GitHub 403,说明 出口 IP 被封。 别折腾代理了,上 SSH。"
→ 第一次听到 "节点不干净" 这个说法
→ 第一次知道 "可以用 SSH 绕过"
第五次尝试:换成 Clash for Windows(标准 7890 端口)
配置:
git config --global http.proxy http://127.0.0.1:7890
git config --global https.proxy http://127.0.0.1:7890
测试:
$web.DownloadString("https://api.github.com")
→ 返回 403 Forbidden
→ 真相大白:
不是我配置错,是节点 IP 本身被 GitHub 拉黑!

成功方案:SSH 密钥配对(野生程序员菜谱,照着做 100% 成功)
核心逻辑:
-
私钥
= 你本地的"钥匙"
-
公钥
= 提前放进 GitHub 的"锁孔"
-
推送时 → 钥匙插锁 → 匹配成功 → 22 端口通道开通
步骤 1:生成密钥对(本地造钥匙)
ssh-keygen -t ed25519 -C "your_email@example.com"
-
提示路径 → 回车(默认 C:\Users\你的名字\.ssh\id_ed25519)
-
提示密码 → 回车两次(不设密码,开发方便)
生成两个文件:
id_ed25519 → 私钥(永不外传)
id_ed25519.pub → 公钥(给 GitHub)
步骤 2:复制公钥
Get-Content $HOME\.ssh\id_ed25519.pub | clip
整行内容已复制(从 ssh-ed25519 开头到邮箱结尾)
步骤 3:把公钥添加到 GitHub(放锁到门上)
-
打开浏览器 → https://github.com/settings/keys
-
点击 "New SSH key"
-
填写:
-
Title
: My-Laptop-2025
-
Key
: Ctrl+V 粘贴
-
-
点击 Add SSH key
步骤 4:测试连接(敲门试锁)
ssh -T git@github.com
-
第一次会问 yes/no → 输入 yes
-
成功输出:
Hi username! You've successfully authenticated...
步骤 5:切换仓库为 SSH 协议
cd E:\AIGC_design\hetong
git remote remove origin
git remote add origin git@github.com:username/hetong_20251027.git
验证:
git remote -v
步骤 6:推送代码(开门推货)
git add .
git commit -m "init: 合同时空系统,SSH 上线" --allow-empty
git branch -M main
git push -u origin main
以后更新:三行永不过时
git add .
git commit -m "优化合同生成"
git push
无需代理 | 无需换节点 | 无需 403
附加:.gitignore(防上传垃圾)
新建 .gitignore 文件:
