github克隆走v2ray代理的配置

前提条件

v2ray已经配置好,可以科学上网
如果是linux系统,则需要使用qv2ray(内核为v2ray)

查看v2ray侦听ip和端口

可以在v2ray设置里查看或者修改
我的是设置成了
ip 127.0.0.1
socks侦听端口为1200
http侦听端口为1600
socks端口适用性更广,可以都设置为socks端口

配置Clone with HTTPS

全局配置

法一
git config --global http.proxy http://127.0.0.1:1600
或者http端口1200也行
法二
git config --global http.proxy socks5://127.0.0.1:1200
必须为socks端口
法三
git config --global http.proxy socks5h://127.0.0.1:1200
必须为socks端口

注意没有 https.proxy 设置
ubuntu20.04实测没问题,其他发行版应该也没问题。

限定到从github克隆(可不配置)

如果想要限定为github.com

git config --global http.https://github.com.proxy http://127.0.0.1:1600

配置Clone with SSH

使用监听的socks端口,我的是1200

  • 修改~/.ssh/config文件,没有则创建
    并添加如下内容
    ProxyCommand nc -X 5 -x 127.0.0.1:1200 %h %p

  • linux中也可使用如下指令添加
    echo "Host github.com" >> ~/.ssh/config
    echo "ProxyCommand nc -X 5 -x 127.0.0.1:1200 %h %p" >> ~/.ssh/config

上面的 IP(v2ray监听ip,127.0.0.1)、端口(v2ray监听socks端口,1200)、域名换成对应正确的就好。
注意ip,端口一定要是你自己v2ray里设置的

查看代理

查看所有全局配置
git config -l

查看全局http代理配置
git config --global --get-regexp http.*

查看本地仓库的配置
(If you are in a locally cloned repository folder then you drop the –global and see all current config:)

git config --get-regexp http.*

取消代理

取消全局代理
git config --global --unset **http.proxy**
取消限定github的代理
git config --global --unset http.https://github.com.proxy