Git设置和取消代理(SSH和HTTP、HTTPS多种方式)

2021-03-06 2545点热度 0人点赞 0条评论

前言

因为众所周知的原因,在使用https://gitlab.comhttps://github.com做Git操作的时候(git clone, git pull, git push)会很慢,或者有时候甚至一直卡住。

问题解决(HTTP HTTPS的方案)

假设你已经安装了本地或者路由器上的代理,例如socks5代理:127.0.0.1:7891

打开命令行,输入:

git config --global http.proxy socks5://127.0.0.1:7891
git config --global https.proxy socks5://127.0.0.1:7891

如果是http代理(127.0.0.1:10809):

git config --global https.proxy http://127.0.0.1:10809
git config --global https.proxy http://127.0.0.1:10809

去掉代理:

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

如果只针对github做代理:

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

取消代理(或者找到config文件直接修改也可以,config文件在~/.gitconfig):

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

问题解决SSH的部分

以上.gitconfig的方案,如果针对ssh方式是不管用的,例如 git clone [email protected]:xxx/xxx,需要修改ssh的配置文件~/.ssh/config

增加如下:

ProxyCommand nc -x 127.0.0.1:7891 %h %p

同样可以针对github做设置(防止正常的SSH也走代理)

Host github.com
  User git
  ProxyCommand nc -x 127.0.0.1:7891 %h %p

加上以后,可以用调试命令试一下:

ssh -vvvvA [email protected]

 

admin

这个人很懒,什么都没留下

文章评论

您需要 登录 之后才可以评论