git代理配置

HTTP形式

走http代理

1
2
3
4
5
6
git config --global http.proxy "http://127.0.0.1:8080"
git config --global https.proxy "http://127.0.0.1:8080"

# github

git config -global http.https://github.com.proxy "http://127.0.0.1:8080"

走socks5代理

1
2
3
4
5
git config --global http.proxy "socks5://127.0.0.1:1080"
git config --global https.proxy "socks5://127.0.0.1:1080"

# github
git config -global http.https://github.com.proxy "socks5://127.0.0.1:1080"

取消代理

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

脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash
# git 代理设置
# -p 配置全代理 -h 配置代理github -r 关闭代理 -l 显示配置信息

while getopts "p h r l" opt
do
case $opt in
p)
git config --global http.proxy 'socks5://127.0.0.1:1080';
git config --global https.proxy 'socks5://127.0.0.1:1080';
echo "成功配置git代理为:socks5://127.0.0.1:1080"

;;
h)
git config --global http.https://github.com.proxy socks5://127.0.0.1:1080
echo "成功配置github的git代理为:socks5://127.0.0.1:1080"
;;
r)
git config --global --unset http.proxy;
git config --global --unset https.proxy;
git config --global --unset http.https://github.com.proxy;
echo "成功取消git代理"
;;
l)
git config -l
;;
?)
echo "该脚本未定义该选项目"
exit 1
;;
esac
done

SSH形式

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

1
2
3
4
5
6
7
8
9
# 代理地址
Host github.com
HostName github.com
User git
# 走 HTTP 代理
# ProxyCommand socat - PROXY:127.0.0.1:%h:%p,proxyport=8080

# 走 socks5 代代理
# ProxyCommand nc -v -x 127.0.0.1:1080 %h %p
-------------本文结束感谢阅读-------------

欢迎关注我的其它发布渠道