# 设置代理

##### 全局设置（不推荐）

如果有使用到私有仓库，使用代理可能反而无法正常访问

```bash
# 使用http代理 
git config --global http.proxy http://127.0.0.1:58591
# 目前git仓库为了安全一般都是使用的https协议，因此也可以只设置这一项
git config --global https.proxy https://127.0.0.1:58591
#使用socks5代理
git config --global http.proxy socks5://127.0.0.1:51837
git config --global https.proxy socks5://127.0.0.1:51837
```

##### 只对Github代理（推荐）

一般也就是当前网络环境无法正常访问github时才会需要设置代理

```
#使用socks5代理（推荐）
git config --global http.https://github.com.proxy socks5://127.0.0.1:51837
#使用http代理（不推荐）
git config --global http.https://github.com.proxy http://127.0.0.1:58591
```

最终会在`${HOME}/.gitconfig`文件中生成如下配置片段

```ini
[http "https://github.com"]
	proxy = socks5://127.0.0.1:51837
```

##### 取消代理

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

##### 参考资料：

- [【知乎】 - 设置代理解决github被墙](https://zhuanlan.zhihu.com/p/481574024)