挂VPN/代理后git依然无法XXX
原因:代理对终端/git不起作用
办法:为git设置代理或者为终端设置代理,本文仅讲解对git设置代理的方法
基础知识
如果要对所有的仓库都设置代理,那么加--global
选项,如果仅对某个仓库设置代理,则不加此选项。
--global
选项会作用于~/.gitconfig
文件中的内容,不加此选项将作用与指定仓库目录下的.git/config
文件
设置全局代理
# git config --global http.proxy http://proxyUsername:proxyPassword@proxy.server.com:port
# git config --global https.proxy http://proxyUsername:proxyPassword@proxy.server.com:port
# git config --global 协议.proxy 协议://ip地址:端口号
git config --global http.proxy http://127.0.0.1:7890
git config --global https.proxy http://127.0.0.1:7890
git config --global http.proxy 'socks5://127.0.0.1:7891'
git config --global https.proxy 'socks5://127.0.0.1:7891'
# 取消代理
git config --global --unset http.proxy
git config --global --unset https.proxy
设置仅针对某个网站的代理:比如GitHub
#只对github.com
git config --global http.https://github.com.proxy http://127.0.0.1:7890
git config --global http.https://github.com.proxy socks5://127.0.0.1:7891
#取消代理
git config --global --unset http.https://github.com.proxy
只在clone指定的存储库上使用代理,在其他存储库上则不需要
# $ git clone https://仓库地址 --config "https.proxy=proxyHost:proxyPort"
git clone https://github.com/skywind3000/asyncrun.vim.git --config https.proxy=https://127.0.0.1:7890
参考文献
https://gist.github.com/evantoli/f8c23a37eb3558ab8765
https://git-scm.com/docs/git-config/2.9.5