Git连接Github远程仓库的代理设置

在使用git命令克隆github远程仓库的代码时,遇到了如下443错误,原因是网络连接问题导致无法访问 GitHub 服务器。

考虑到可能是代理设置的问题

  • 查看全局代理设置
bash 复制代码
git config --global --get http.proxy
git config --global --get https.proxy

# 如果有返回结果,这说明已配置代理
# http://127.0.0.1:7890
# https://127.0.0.1:7890

# 若未返回任何内容,则表示当前没有全局代理配置
  • 若使用代理,需确保 Git 已正确配置代理:
bash 复制代码
# 设置代理(替换为你的代理地址)
# 默认127.0.0.1:7890

# 设置HTTP代理
git config --global http.proxy http://代理地址:端口号
# 设置HTTPS代理
git config --global https.proxy https://代理地址:端口号

# 仅让 GitHub 走代理
git config --global http.https://github.com.proxy http://代理地址:端口
git config --global https.https://github.com.proxy https://代理地址:端口
  • 若不需要代理,可清除代理设置:
bash 复制代码
# 清除全局 HTTP 代理
git config --global --unset http.proxy
# 清除全局 HTTPS 代理
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
  • 验证代理是否生效

可以通过克隆一个 GitHub 仓库(或执行 git fetch)来测试代理是否工作,例如:

bash 复制代码
git clone https://github.com/githubtraining/hellogitworld.git

配置后,只有访问 github.com 相关的仓库时才会走代理,访问其他仓库(如 GitLab、Gitee 等)则不会受影响。

相关推荐
大卫小东(Sheldon)13 小时前
GIM 2.0 发布:真正让 AI 提交消息可定制、可控、可项目级优化
git·rust·gim
知识即是力量ol16 小时前
研发实战:Git 规范化开发全流程指南
git·gitee·github
我是一只代码狗16 小时前
idea创建分支
git
知识即是力量ol18 小时前
Git 快速入门 (实习生视角)
git·gitee·github
Dontla18 小时前
Git撤销上一次提交(撤销提交,Git回退提交)git reset、git revert
git
wdfk_prog18 小时前
解决 `git cherry-pick` 引入大量新文件的问题
大数据·git·elasticsearch
fu的博客21 小时前
Git从删库到跑路
git·gitee·github
要加油哦~21 小时前
git 报错 | husky - pre-commit hook exited with code 1 解决
git
知识即是力量ol21 小时前
Git 实战指南:从分支管理到冲突解决
git·github·源代码管理
基于底层的菜鸟21 小时前
如何在VS code中为GitHub Copilot 添加SKill
github