Git 443解决方案

Posted by Blog on October 22, 2025

Git Push 443 超时问题解决记录

> 适用于:Windows / macOS / Linux
> 场景:能 ping github.com,但 git pushport 443: Connection timed outCould not connect to 127.0.0.1:7890


一、现象时间线

阶段 报错原文 初步判断
git push Failed to connect to github.com port 443 ... Could not connect to server 被强制走 443,TCP 连不上
② 换 SSH 地址后 ssh: connect to host github.com port 443: Connection timed out SSH 也被劫持到 443
ssh -T git@github.com Hi AnonymousDotNet! ... 22 口本身畅通,认证无问题
git config --get core.sshCommand ssh -o Port=443 全局 SSH 被锁死 443
⑤ 改回 HTTPS 后 Could not connect to 127.0.0.1 port 7890 本地代理端口未启动

二、根本原因

  1. 全局 Git 配置残留
    • core.sshCommand = ssh -o Port=443 → 所有 SSH 被转到 443
    • http.proxy / https.proxy = 127.0.0.1:7890 → HTTPS 时走本地代理,代理未运行
  2. 网络层对 443 端口的 SSH 协议丢包,导致“能 ping 通 GitHub,但 push 超时”。

三、解决步骤(最终落地)

目标:恢复“干净”默认通道,优先用 SSH 22。

操作 命令 备注
① 清全局 SSH 端口强制 git config --global --unset core.sshCommand 让 SSH 回归默认 22
② 清代理残留 git config --global --unset http.proxy && git config --global --unset https.proxy 防止 HTTPS 时再找 7890
③ 远程地址切回 SSH git remote set-url origin git@github.com:<user>/<repo>.git 一条命令切回 SSH 模式
④ 验证连通 ssh -T git@github.com 应立刻返回 Hi <user>!
⑤ 推送 git push origin main 成功,不再经过任何代理

四、后续加固(可选)

  1. 锁定 22 端口,防止再被工具修改
    ~/.ssh/config
    ```text Host github.com Hostname github.com Port 22