给github设置代理

1 引言

本文详细介绍了在 Linux 环境下配置和使用网络代理的步骤。包括使用环境变量设置代理的方法、在 Git 中配置代理的常用方法以及一些调试工具。这些内容对于需要在网络受限环境下使用 Git 的用户非常实用。

2 配置代理

shell 复制代码
export http_proxy=http://host:port/  
export https_proxy=$http_proxy  
export ftp_proxy=$http_proxy  
export rsync_proxy=$http_proxy  
export all_proxy=$http_proxy  
export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"

3 git 设置 http 代理

最常用的访问 git 的方式是 http 方式,形如:

shell 复制代码
$ git clone https://github.com/xxx/yyy/

在这种情况下,正常连接需要设置 http proxy。

3.1 设置
shell 复制代码
$ git config --global http.proxy http://host:port
$ git config --global https.proxy https://host:port
3.2 查看当前配置
shell 复制代码
$ git config --global -l
3.3 取消代理
shell 复制代码
$ git config --global --unset http.proxy
$ git config --global --unset https.proxy

4 设置 ssh 代理

我们也常常使用 ssh 方式操作 gihub 项目,形如:

shell 复制代码
git clone git@github.com:xxx/yyy.git

这种方式使用 ssh 与 github 建立连接,无法使用 http proxy 设置,具体设置方法如下:

shell 复制代码
$ vi ~/.ssh/config

编辑如下:

Host github.com
  HostName github.com
  User git
  ProxyCommand nc -x host:port %h %p

(注意:这里的 host:port 不是 http 代理,是 socks 代理)

测试 nc 命令是否正常

shell 复制代码
$ nc -x host:port github.com 22

测试 git 的 ssh 方式是否正常

shell 复制代码
$ ssh -T git@github.com
相关推荐
研究点啥好呢5 分钟前
Github热榜项目推荐 | Fireworks Tech Graph:告别手动绘图时代
python·开源·github·claude·skills
Jempo M1 小时前
为GitHub Copilot手搓一个可调用工具的AI Agent
人工智能·github·copilot
of Watermelon League1 小时前
SQL server配置ODBC数据源(本地和服务器)
运维·服务器·github
❀͜͡傀儡师1 小时前
GitHub Copilot for VS Code 中文使用完整教程
vscode·github·copilot
MapleWan320631 小时前
告别 AI IDE 配置碎片化:用 MSR-cli 打造你的本地 MCP / Rules / Skills 统一仓库
python·github
belingud1 小时前
我经常只想从 GitHub 仓库里拿几个文件或某个目录,于是做了 `gh-download`
github
sirleaf2 小时前
GitHub Copilot 学生认证详细教程
github·copilot
darkb1rd3 小时前
html-ppt-skill:纯静态 HTML 构建专业演示文稿指南
开源·github·好物分享
A小码哥17 小时前
github上 160K star 的 superpowers 插件使用经验与场景总结
github
Hommy8817 小时前
【开源剪映小助手】视频生成流程
开源·github·音视频·剪映小助手