文章摘要
本文介绍了如何通过Git内网代理访问外网的相关配置,重点包括以下内容:
1. **配置Git代理**:
- 以http代理为例,配置Git的http和https代理,例如:
```bash
git config --global http.proxy http://username:password@proxy.server.com:8080
git config --global https.proxy http://username:password@proxy.server.com:8080
```
2. **替换Git协议**:
如果企业内网防火墙屏蔽Git://协议,可以尝试将Git协议替换为https,例如:
```bash
git config --global url."https://github.com/".insteadOf git@github.com:
git config --global url."https://".insteadOf git://
```
3. **取消https证书验证**:
在企业访问外网时,有时会强制替换https证书,导致错误。可以通过以下命令跳过证书验证:
```bash
git config --global http.sslVerify false
```
此外,文章还提供了临时和永久设置配置的方法,建议将配置写入`.gitconfig`文件中以实现永久代理设置。
这篇文章为需要绕过网络限制或解决证书验证问题的用户提供了实用的配置方法。更多相关内容可参考之前的文章或继续阅读相关文章。
目录git通过内网代理,访问外网的相关配置1 配置git代理(以http代理为例)2 替换git协议为https协议3 取消https协议的证书验证补充:git设置代理临时设置永久设置
git config –global http.proxy http://<username>:<password>@<proxy.server.com>:<8080>
git config –global https.proxy http://<username>:<password>@<proxy.server.com>:<8080>
git config –global https.proxy http://<username>:<password>@<proxy.server.com>:<8080>
在有些企业的内网,由于git请求与ssh访问类似,防火墙会屏蔽git://协议的访问请求,如果git://无法访问,可尝试更换为https://协议
git config –global url.”https://github.com/”.insteadOf git@github.com:
git config –global url.”https://”.insteadOf git://
git config –global url.”https://”.insteadOf git://
在有些企业访问外网的代理,会强行把https的证书进行替换,导致https访问时,出现证书错误。如果想跳过证书错误,需要把git全局的证书验证关闭。
git config –global http.sslVerify false
打开 Git Bash,使用命令临时设定socks代理:
git config –global http.proxy ‘socks5://127.0.0.1:socks5端口号’
git config –global https.proxy ‘socks5://127.0.0.1:socks5端口号’
git config –global https.proxy ‘socks5://127.0.0.1:socks5端口号’
或者http代理:
git config –global http.proxy ‘http://127.0.0.1:http端口号’
git config –global https.proxy ‘https://127.0.0.1:https端口号’
git config –global https.proxy ‘https://127.0.0.1:https端口号’
若想要设置代理永久生效,则可以把它写入 .gitconfig 文件中。
使用 vi 打开 .gitconfig 文件:
vi ~/.gitconfig
写入下列配置(建议在最末写入):
[http]
proxy=socks5://127.0.0.1:socks5端口号
proxy=http://127.0.0.1:http端口号
[https]
proxy=socks5://127.0.0.1:socks5端口号
proxy=https://127.0.0.1:http端口号
proxy=socks5://127.0.0.1:socks5端口号
proxy=http://127.0.0.1:http端口号
[https]
proxy=socks5://127.0.0.1:socks5端口号
proxy=https://127.0.0.1:http端口号
修改后重启 git ,使配置生效:
git config -l –global
查看当前代理:
git config -l
可以看到自己所配置的端口信息,则说明配置成功。

到此这篇关于git通过内网代理,访问外网的相关配置的文章就介绍到这了,更多相关git内网代理访问外网内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
您可能感兴趣的文章:Git设置和取消代理的方法
© 版权声明
文章版权归作者所有,未经允许请勿转载。