前言
终端git速度有点有时候很慢,一直想让让终端走代理的方式来加快速度,如果只是为了设置git的话可以直接在文章最后找到git的设置代理的方法。
准备
Linux终端、酸酸乳等
方式
方式一
只作用于终端
终端中直接运行
# http
export http_proxy=http://127.0.0.1:port
# https
export https_proxy=http://127.0.0.1:port
如果是socket5协议的话(本地端口一般1080)
export http_proxy="socks5://127.0.0.1:1080"
export https_proxy="socks5://127.0.0.1:1080"
方式二
写进配置文件(~/.bashrc或者使用zsh的写进~/.zshrc里面)
export http_proxy="http://localhost:port"
export https_proxy="http://localhost:port"
如果使用socket5 1080端口
export http_proxy="socks5://127.0.0.1:1080"
export https_proxy="socks5://127.0.0.1:1080"
# 或者直接使用全部
export ALL_PROXY=socks5://127.0.0.1:1080
最后在重新启用一下配置文件
source ~/.bashrc
#或者
source ~/.zshrc
此外还可以使用alias**
加速git命令
- 使用代理
git config --global http.proxy 'socks5://127.0.0.1:1080'
git config --global https.proxy 'socks5://127.0.0.1:1080'
- 取消代理
git config --global --unset http.proxy
git config --global --unset https.proxy
- 上面的是全局代理,这个可以使用仅代理Github,不影响Coding或者Gitee等国内仓库使用
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
此外
检查是否代理成功
#检查全局
curl ip.gs
#或者
curl ip.sb
#检查代理是否有效
http_proxy=socks5://localhost:1080 curl ip.gs
#或者
https_proxy=socks5://localhost:1080 curl ip.gs