Git代理配置

本机 v2rayN 开的服务,默认 http 端口为 10809,socks端口为10808

image-20231103104716115

image-20231103111822575

接管配置

全部接管

1
2
3
4
5
git config --global http.proxy socks5://127.0.0.1:端口号
git config --global https.proxy socks5://127.0.0.1:端口号
#比如端口号为10808,执行下面的命令即可
# git config --global http.proxy socks5://127.0.0.1:10808
# git config --global https.proxy socks5://127.0.0.1:10808

image-20231103111154552

接管 Github

1
2
3
4
git config --global http.https://github.com.proxy socks5://127.0.0.1:端口号
git config --global https.https://github.com.proxy socks5://127.0.0.1:端口号
#git config --global http.https://github.com.proxy socks5://127.0.0.1:10808
#git config --global https.https://github.com.proxy socks5://127.0.0.1:10808

image-20231103111220936

检查设置

全部接管的检查

1
2
git config --global --get http.proxy
git config --global --get https.proxy

image-20231103111242252

接管 Github 的检查

1
2
git config --global --get http.https://github.com.proxy
git config --global --get https.https://github.com.proxy

image-20231103111305275

还原设置

取消全部接管

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

取消接管 Github

1
2
git config --global --unset http.https://github.com.proxy
git config --global --unset https.https://github.com.proxy

SSH代理

修改 ~/.ssh/config 文件(不存在则新建):

~就是%userprofile%,也就是用户目录

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 端口号要替换
ProxyCommand connect -S 127.0.0.1:10808 -a none %h %p

Host github.com
User git
Port 22
Hostname github.com
# 注意修改路径为你的路径
IdentityFile "C:\Users\Administrator.SC-201902031211\.ssh\id_rsa"
TCPKeepAlive yes

Host ssh.github.com
User git
Port 443
Hostname ssh.github.com
# 注意修改路径为你的路径
IdentityFile "C:\Users\Administrator.SC-201902031211\.ssh\id_rsa"
TCPKeepAlive yes

image-20231103110016303

测试

最后下载一个文件测试一下

未配置前,下载了好久都下载不下来

image-20231103111540029

配置后

image-20231103111613086

这个文件大小总共3G

image-20231103121456826

image-20231103121515232

参考文章


Git代理配置
http://example.com/2023/11/03/Git代理配置/
作者
Deng ErPu
发布于
2023年11月3日
许可协议