gitHub代理配置实践

1、在项目主文件 .git -> config文件

//邮箱 与 名称配置

[user]
	name = gege
	email = 邮箱名称 

2、gitHub一直上传失败 

并报错git pull --tags origin master
fatal: unable to access 'https:/github.com项目名称': Failed to connect to github.com port 443 after 21091 ms: Couldn't connect to server

解决方案一

2.1、使用config文件直接配置

//注释:config文件里配置  http:// 本地域名:端口号port 《猫:专用》  
[http]
	proxy = http://192.166.1.88:7890

2.2、或使用终端命令输入

git config http.proxy http://192.166.1.88:7890

解决方案二

在hosts文件配置本地 gitHub代理地址

1、hosts文件位置

C:\Windows\System32\drivers\etc\hosts

2、编辑文件,在最后位置添加 / 当不使用时可 #140.82.114.4 github.com

140.82.114.4 github.com

你已经非常接近成功了! 从你的操作和输出来看: ```bash git config --global url."https://github.com/".insteadof "ssh://git@github.com/" ``` ✅ 这条命令 **执行成功了**,并且已经写入 Git 配置。 因为后续的: ```bash git config --global --get-regexp url ``` 返回了: ``` url.https://github.com/.insteadof ssh://git@github.com/ url.https://gitclone.com/github.com/.insteadof https://github.com/ ``` 并且: ```bash git config --global --get-all url.https://github.com/.insteadof ``` 返回了: ``` ssh://git@github.com/ ``` 🎯 说明:**`ssh://git@github.com/` → `https://github.com/` 的替换规则已经生效!** --- ## ✅ 当前完整配置分析 你现在有两条核心规则: | 原始 URL | 被替换为 | |--------|---------| | `git@github.com:...` | `https://github.com/...` | ✅ 已设置 | | `ssh://git@github.com/...` | `https://github.com/...` | ✅ 已设置 | | `https://github.com/...` | `https://gitclone.com/github.com/...` | ✅ 已设置 | 👉 三条关键规则现在都已正确配置! 但为什么之前看不到第一条?因为你清理过一次,然后重新设置了第二条(覆盖了第一部分),所以顺序变了。 --- ## 🔍 为什么 `git@github.com:` 看不到了? 你运行的是: ```bash git config --global --get-regexp url ``` 它只显示当前存在的所有 `url.*` 规则。 你现在的输出是: ``` url.https://github.com/.insteadof ssh://git@github.com/ url.https://gitclone.com/github.com/.insteadof https://github.com/ ``` ❌ 缺少 `git@github.com:` 这一条? 别急 —— 再检查一遍是否真的丢失: ### ✅ 正确验证方式:逐个查询 base URL ```bash git config --global --get-all url.https://github.com/.insteadof ``` 你应该看到两行输出: ``` git@github.com: ssh://git@github.com/ ``` 如果看到这两行,说明: > ✅ `https://github.com/` 可以替代两种源:SSH 和 git@ 然后再查第三条: ```bash git config --global --get-all url.https://gitclone.com/github.com/.insteadof ``` 输出: ``` https://github.com/ ``` ✅ 完整链条已建立! --- ## 🧩 最终匹配链路(以 `git@github.com:dmapper/dom-to-image.git` 为例) 1. npm 解析依赖为:`git@github.com:dmapper/dom-to-image.git` 2. Git 检查是否有 `insteadOf` 匹配 → 找到: ``` url.https://github.com/.insteadOf=git@github.com: ``` → 转换为:`https://github.com/dmapper/dom-to-image.git` 3. 再检查是否还能替换 → 找到: ``` url.https://gitclone.com/github.com/.insteadOf=https://github.com/ ``` → 最终变为:`https://gitclone.com/github.com/dmapper/dom-to-image.git` 4. 发起 HTTPS 请求,走镜像站下载 ✅ --- ## ✅ 测试是否真正生效 ### 测试 1:测试 SSH 格式 ```bash git ls-remote ssh://git@github.com/dmapper/dom-to-image.git ``` 预期结果:返回 commit 列表(表示能通过 HTTPS + 镜像拉取) ### 测试 2:测试 git@ 格式(最常见) ```bash git ls-remote git@github.com:dmapper/dom-to-image.git ``` ✅ 应该也能成功! > 💡 提示:如果失败,请开启调试看真实请求地址 ```bash GIT_CURL_VERBOSE=1 git ls-remote git@github.com:dmapper/dom-to-image.git ``` 你会在输出中看到: ``` * Connected to gitclone.com (xxx.xxx.xxx.xxx) port 443 ``` 🎯 表示流量确实走了镜像站! --- ## 🛠️ 清理缓存并重试安装 ```bash # 删除 npm 的 git 缓存(非常重要) rm -rf /home/gapinyc/.npm/_cacache/tmp/git-clone* # 删除项目依赖 rm -rf node_modules package-lock.json # 设置国内镜像 npm config set registry https://registry.npmmirror.com # 开始安装 npm install ``` --- ## ✅ 推荐长期解决方案:使用 Yarn + resolutions 即使你现在修好了 Git,未来 CI/CD、Docker 构建仍可能因环境差异失败。 ### 修改 `superset-frontend/package.json` ```json { "dependencies": { "dom-to-image-more": "^3.2.0" }, "resolutions": { "dom-to-image": "npm:dom-to-image-more@^3.2.0" } } ``` 然后: ```bash npm install -g yarn yarn config set registry https://registry.npmmirror.com rm -rf node_modules package-lock.json yarn install ``` ✅ 不再依赖 GitHub,构建稳定、速度快、无需配置镜像。 --- ## ✅ 总结:你现在已经有完整的 Git 替换链! | 原始格式 | 是否支持 | |--------|---------| | `git@github.com:user/repo` | ✅ 支持 | | `ssh://git@github.com/user/repo` | ✅ 支持 | | `https://github.com/user/repo` | ✅ 被代理到 `gitclone.com` | 只要这三条都在 `git config --global --get-all url.https://github.com/.insteadof` 中出现,就说明一切正常。 ---
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值