一、通过命令配置全局代理

此处我的服务器设置 Trojanhttp协议,端口号10887,具体的请根据自己的软件设置

1
2
3
4
5
6
7
8
9
10
11
12
13
# 文档中我的代理服务器是http协议的,如果你使用的socks协议就将 http://127.0.0.1:10887 替换为socks5://127.0.0.1:1080

# 对github进行配置
git config --global http.https://github.com.proxy http://127.0.0.1:10887
git config --global https.https://github.com.proxy http://127.0.0.1:10887

# 对谷歌的webp库地址进行配置
git config --global http.https://chromium.googlesource.com.proxy http://127.0.0.1:10887
git config --global https.https://chromium.googlesource.com.proxy http://127.0.0.1:10887

# 配置所有 git
git config --global http.proxy http://127.0.0.1:10887
git config --global https.proxy http://127.0.0.1:10887

同时,如果在输入这条命令之前,已经输入全局proxy的话,可以输入进行取消

1
2
3
4
5
6
7
8
9
10
11
# 移除对github配置
git config --global --unset http.https://github.com.proxy
git config --global --unset https.https://github.com.proxy

# 移除对谷歌的webp库地址的配置
git config --global --unset http.https://chromium.googlesource.com.proxy
git config --global --unset https.https://chromium.googlesource.com.proxy

# 移除 全局 git 配置
git config --global --unset http.proxy
git config --global --unset https.proxy

验证

1
2
3
4
5
# 查看git 全局配置
$ git config --global -l

# 再次克隆即可加速,速度取决于你的代理速度
$ git clone https://github.com/gin-gonic/gin.git

二、通过配置文件设置全局代理

默认git使用的配置文件路径在 ~/.gitconfig

编辑配置文件~/.gitconfig

1
$ vim ~/.gitconfig

添加以下代理内容 http://127.0.0.1:10887 代理服务器地址修改为你自己的

1
2
3
4
5
6
7
8
9
10
11
[user]
name = xxxx
email = xxxx@163.com
[http "https://github.com"]
proxy = http://127.0.0.1:10887
[https "https://github.com"]
proxy = http://127.0.0.1:10887
[http]
proxy = http://127.0.0.1:10887
[https]
proxy = http://127.0.0.1:10887
1
2
3
4
5
// 查看git 全局配置
$ git config --global -l

# 再次克隆即可加速,速度取决于你的代理速度
$ git clone https://github.com/gin-gonic/gin.git