Git 通过 SOCKS5 代理配置指南

Git 代理配置指南

使用 SOCKS5 代理进行 Git 操作可以帮助提高连接速度或绕过网络限制。以下是针对不同连接方式的代理配置方法:

1. Git HTTP/HTTPS 代理配置

当使用 HTTP 或 HTTPS 连接 Git 仓库时,可以直接在 Git 配置中设置 SOCKS5 代理。

git config --global http.proxy 'socks5://127.0.0.1:7891'
git config --global https.proxy 'socks5://127.0.0.1:7891'

清除代理

git config --global --unset http.proxy
git config --global --unset https.proxy

如果你想检查代理设置是否确实被清除,可以使用以下命令来查看当前的 Git 配置:

git config --global --list

2. SSH 代理配置

使用 SSH 方式连接 Git 仓库时,可以通过编辑 ~/.ssh/config 文件来配置 SOCKS5 代理。

  1. 编辑 SSH 配置文件
    打开或创建 SSH 配置文件:
vi ~/.ssh/config

在配置文件中添加以下内容:

Host github.com
    HostName github.com
    User git
    ProxyCommand nc -x 127.0.0.1:7891 %h %p

其中 127.0.0.1:7891 是 SOCKS5 代理的地址和端口。请根据您的代理服务器的具体地址和端口进行相应的替换。

无标签
评论区
头像
文章目录