git代理设置

本文最后更新于:1 天前

让git的速度变快。

前言

用git时有时会比较慢,很烦,所以找了下,发现git还真能走代理。这下速度真是起飞,舒服了。
于是就记录一下,方便自己以后来查。

代理设置

查看当前代理设置

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

设置当前代理

这里是把代理设置成http://127.0.0.1:1080 或 socket5://127.0.0.1:1080。

根据自己的实际情况改吧。

1
2
3
4
5
6
#http和https走socks5协议,1080端口修改成自己的本地代理端口
git config --global http.proxy 'socks5://127.0.0.1:1080'
git config --global https.proxy 'socks5://127.0.0.1:1080'
#http和https走http协议的代理,1081端口修改成自己的本地代理端口
git config --global http.proxy 'http://127.0.0.1:1081'
git config --global https.proxy 'http://127.0.0.1:1081'

删除 proxy

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

当然了,以上的配置是对所有的git都走代理,有些时候我们只想让github走代理的时候该怎么办呢?

只让github走代理

1
2
3
4
5
6
7
# http和https走socks5协议,1080端口修改成自己的本地代理端口
git config --global http.https://github.com.proxy socks5://127.0.0.1:1080
git config --global https.https://github.com.proxy socks5://127.0.0.1:1080

# http和https走http协议,1081端口修改成自己的本地代理端口
git config --global http.https://github.com.proxy https://127.0.0.1:1081
git config --global https.https://github.com.proxy https://127.0.0.1:1081

其他相关命令

1
2
3
4
# 查看所有配置
git config -l
# 该命令和下面这个方式等价
git config --list

参考

一招 git clone 加速


git代理设置
https://www.yikakia.com/git代理设置/
作者
Yika
发布于
2020年3月2日
许可协议