git为github设置代理的优雅方式

1.仅clone代码

方案:在地址前加https://github.91chi.fun/
如: git clone https://github.com/hybridgroup/gocv.git
改为:git clone https://github.91chi.fun/https://github.com/hybridgroup/gocv.git

2. 为https/https协议上的仓库设置

ps: 需要根据个人情况设置好端口号,如果是sock,则把https或http换为sock
git config --global http.https://github.com.proxy http://127.0.0.1:7890
git config --global https.https://github.com.proxy http://127.0.0.1:7890

3. 为ssh协议上的仓库设置代理

即这种形式clone下来的仓库:
git clone [email protected]:hybridgroup/gocv.git

  • linux or mac
$ vim ~/.ssh/config
Host github.com
ProxyCommand nc -X connect -x 127.0.0.1:7890 %h %p #-S为socks
HostName %h
Port 22
User git
IdentityFile  ~/.ssh/id_rsa
IdentitiesOnly yes
  • windows:
    编辑用户文件夹/.ssh/config
Host github.com
ProxyCommand connect -H 127.0.0.1:7890 %h %p   #-S为socks
HostName %h
Port 22
User git
IdentityFile  ~/.ssh/id_rsa 
IdentitiesOnly yes

PS: 方式3参考了:Issue #1563 · Fndroid/clash_for_windows_pkg (github.com)

你可能感兴趣的:(git为github设置代理的优雅方式)