挂代理后git依然无法XXX

挂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

  • 3
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值