Git自动检测系统代理设置 [英] Git to auto-detect the system proxy settings

查看:615
本文介绍了Git自动检测系统代理设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常更改具有不同代理设置的地方,或者只是从WiFi更改为具有不同代理的电缆连接.

I am often changing places that have different proxy settings, or simply changing from WiFi to cable connection with a different proxy.

当我使用OsX时,很容易从网络配置切换到其他配置.但是git在 .gitconfig 文件中有自己的设置,我很累每次都修改该文件.

As I am using OsX, it is easy to switch from a network configuration to another. But git has its own setting in the .gitconfig file and I am tired modifying that file every time.

是否可以将代理(也许从系统变量传递)到 .gitconfig 文件,或具有诸如 auto-detect system-proxy 还是类似的?

Is there a way to pass the proxy (maybe from a system variable?) to the .gitconfig file, or have a setting such as auto-detect, system-proxy or similar?

推荐答案

根据git-config(1)手册页,git默认已使用标准的http_proxy环境变量:

According to the git-config(1) man page, git already uses the standard http_proxy environment variable by default:

   http.proxy
       Override the HTTP proxy, normally configured using the http_proxy, https_proxy, and all_proxy environment variables (see
       curl(1)). This can be overridden on a per-remote basis; see remote.<name>.proxy

因此,如果在您的环境中适当地设置了http_proxy,则应该全部设置好.

So if you set http_proxy appropriately in your environment, you should be all set.

更新(适用于lingceng)

您可以验证git是否遵守http_proxy环境变量,如下所示:

You can verify that git respects the http_proxy environment variable like this:

$ export http_proxy=http://proxy.example.com:3128
$ export GIT_CURL_VERBOSE=1
$ git clone http://git.kernel.org/pub/scm/boot/syslinux/syslinux.git
Cloning into 'syslinux'...
* Couldn't find host git.kernel.org in the .netrc file; using defaults
*   Trying 10.11.5.35...
* Connected to proxy.example.com (10.11.5.35) port 3128 (#0)
> GET http://git.kernel.org/pub/scm/boot/syslinux/syslinux.git/info/refs?service=git-upload-pack HTTP/1.1

您可以在倒数第二行中看到git连接到代理而不是直接连接到git.kernel.org的地方.

You can see there in the penultimate line where git connects to the proxy rather than directly connecting to git.kernel.org.

这篇关于Git自动检测系统代理设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆