给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
相关推荐
i学长的猫3 分钟前
obsidian md github站点
github
jack@london1 小时前
使用Railway
github
给老吕螺丝4 小时前
提升国内访问GitHub稳定性的解决方案:Steamcommunity 302工具详解 (Ver.13.0.05+)
经验分享·github
阿里嘎多学长4 小时前
2026-02-25 GitHub 热点项目精选
开发语言·程序员·github·代码托管
黑白极客5 小时前
ACP大模型认证刷题工具开源,助力高效备考
java·ai·github·llama·认证
无限进步_6 小时前
138. 随机链表的复制 - 题解与详细分析
c语言·开发语言·数据结构·算法·链表·github·visual studio
AI大模型..11 小时前
Dify 本地部署安装教程(Windows + Docker),大模型入门到精通,收藏这篇就足够了!
人工智能·程序员·开源·llm·github·deepseek·本地化部署
CoderJia程序员甲14 小时前
GitHub 热榜项目 - 日榜(2026-02-24)
人工智能·ai·大模型·github·ai教程
无名的小白16 小时前
宝塔计划任务实现定时备份Openclaw/Workspace到Github
github
散峰而望17 小时前
C++ 启程:从历史到实战,揭开命名空间的神秘面纱
c语言·开发语言·数据结构·c++·算法·github·visual studio