一、设置全局代理
设置http协议
git config --global http.proxy http://127.0.0.1:47988 git config --global https.proxy https://127.0.0.1:47988
使用上面的命令配置完之后,会在 ~/.gitconfig 文件中多出几行:
[http] proxy = http://127.0.0.1:47988 [https] proxy = http://127.0.0.1:47988
设置socks5协议
git config --global http.proxy socks5://127.0.0.1:53127 git config --global https.proxy socks5://127.0.0.1:53127
使用上面的命令配置完之后,会在 ~/.gitconfig 文件中多出几行:
[http] proxy = socks5://127.0.0.1:53127 [https] proxy = socks5://127.0.0.1:53127
请注意,这里指的是
http/https
协议,也就是git clone https://www.github.com/xxxx/xxxx.git
,这种对于SSH协议,也就是git clone git@github.com:xxxxxx/xxxxxx.git
依旧是无效的检查配置是否生效:
git config --global --get http.proxy git config --global --get https.proxy
取消该设置方法:
git config --global --unset http.proxy git config --global --unset https.proxy
二、设置部分代理
但我不推荐直接用全局代理,因为如果挂了全局代理,这样如果需要克隆coding之类的国内仓库,会奇慢无比!所以我建议使用这条命令,只对github进行代理,对国内的仓库不影响。
设置http协议
git config --global http.http://github.com.proxy http://127.0.0.1:47988 git config --global https.https://github.com.proxy https://127.0.0.1:47988
设置socks5协议
git config --global http.http://github.com.proxy socks5://127.0.0.1:53127 git config --global https.https://github.com.proxy socks5://127.0.0.1:53127
同时,如果在输入这条命令之前,已经输入全局代理的话,可以输入下面的命令进行取消
git config --global --unset http.http://github.com.proxy git config --global --unset https.https://github.com.proxy
检查配置是否生效:
git config --global --get http.http://github.com.proxy git config --global --get https.https://github.com.proxy
取消该设置方法:
git config --global --unset http.http://github.com.proxy git config --global --unset https.https://github.com.proxy