git设置有两种
git config –list
git config –global –list
分辨需要设置的代理
- HTTP 形式:git clone https://github.com/test.git
- SSH 形式:git clone git@github.com:Jack/test.git
一、HTTP形式
Http代理
git config –global http.proxy “http://127.0.0.1:8080“
git config –global https.proxy “http://127.0.0.1:8080“
走 socks5 代理(如 小飞机 or V2xxxx)
git config –global http.proxy “socks5://127.0.0.1:1080”
git config –global https.proxy “socks5://127.0.0.1:1080”
取消设置
git config –global –unset http.proxy
git config –global –unset https.proxy
二、SSH形式
修改~/.ssh/config文件(不存在则新建):
1 | # 必须是 github.com |
对于 Windows 用户,要使用 socks5 代理却没有 nc 的,可以将
1 | ProxyCommand nc -v -x 127.0.0.1:1080 %h %p |
配合上面的修改,我这里分享一个我的自用 Linux 一键切换脚本,将下面代码写入 ~/.bash_profile(其他 bash 程序或电脑系统可能路径不太一样)
1 | function github_on() { |
写完之后运行 source ~/.bash_profile使配置文件生效,使用下面的指令就可以很爽的用啦
1 | github_on |