前言

因为某些原因,Github有时候连不上或者比较慢,我们尝试走SS上Github,但是只限于http网页登录,如果需要Git操作也代理,需要配置一番.

Http方式代理

在$HOME目录下的.gitconfig文件是Git的配置文件,可以添加如下配置:

1
2
[http "https://github.com"]
proxy = socks5://127.0.0.1:1086

socks5的端口号填自己使用的SS工具的 本地Socks5监听端口
或者直接一行命令:

1
git config --global http.https://github.com.proxy socks5://127.0.0.1:1086

端口自行修改

SSH方式代理

在某个地方新建一个脚本,假设为$HOME/.custom_shell/proxy_wrapper
填上如下内容:

1
2
#!/bin/bash
nc -x127.0.0.1:1086 -X5 $*

端口逻辑跟Http方式一样.
再给文件可执行权限:

1
chmod +x $HOME/.custom_shell/proxy-wrapper

最后在$HOME/.ssh/config文件(没有的话直接自己新建一个)里填上如下内容:

1
2
3
4
Host github github.com
Hostname github.com
User git
ProxyCommand $HOME/.custom_shell/proxy-wrapper '%h %p'