设置代理

git config --global http.proxy 'http://127.0.0.1:10800'
git config --global https.proxy 'http://127.0.0.1:10800'

注:此处设置的代理 ip 和端口号都是本地存在的(SS/SSR 默认就是)。

取消代理

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

Git 全局配置文件位置

根配置文件 /etc/gitconfig

Windows 的话在 Git 安装目录下 /mingw64/etc/gitconfig,不过最好不要动这个
当前用户 Git 配置 ~/.gitconfig

在配置文件里面添加以下内容也可以添加代理:

[https]
        proxy = socks5://127.0.0.1:1080
[http]
        proxy = socks5://127.0.0.1:1080

遇到的坑

设置了代理之后很容易碰到一个问题:Git Push 提示不支持具有 Socks5 方案的代理

具体 Git 相关的内容建议参考 Pro Gitopen in new window