给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 [email protected]: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 [email protected]
相关推荐
HelloGitHub1 小时前
3 个超火的开源项目「GitHub 热点速览」
开源·github
JinSo2 小时前
create-easy-editor —— 快速搭建你的可视化编辑器
前端·前端框架·github
bubiyoushang8886 小时前
解决 Git 访问 GitHub 时的 SSL 错误
git·github·ssl
tonngw8 小时前
【Mac 从 0 到 1 保姆级配置教程 16】- Docker 快速安装配置、常用命令以及实际项目演示
macos·docker·容器·开源·github·docker desktop·orbstack
海码00710 小时前
【版本控制】Git 和 GitHub 入门教程
git·github
网硕互联的小客服13 小时前
503 Service Unavailable:服务器暂时无法处理请求,可能是超载或维护中如何处理?
服务器·git·github
abcnull15 小时前
github开源协议选择
git·github·开源协议
安庆平.Я17 小时前
git互联GitHub 使用教程
git·github
掘金安东尼18 小时前
字节-Trae、阿里-通义灵码、腾讯-CodeBuddy,为什么都在“卷”AI编码?
面试·llm·github
独立开阀者_FwtCoder20 小时前
Cursor 1.0 重磅发来袭(毛骨悚然,开始学习你如何编码)
前端·javascript·github