我在公司防火墙后面使用git,并且我使用http.proxy --global config成功克隆了外部项目.
当我想在Intranet上通过http克隆时,我的问题出现了.我怀疑代理配置会干扰Intranet请求.
我知道我可以在使用内部网之前重置配置,但这不是非常用户友好.
我也看到了这个答案,但它似乎只适用于现有的存储库.
有没有办法只为一个命令调用停用代理使用?在这种情况下,初始克隆?
Von*_*onC 35
我总是这样说:
no_proxy=.mycompany
Run Code Online (Sandbox Code Playgroud)
(export如果我在Unix上,或set在Windows上简单)
绕过以" .mycompany" 结尾的所有Intranet URL的代理就足够了.
请参阅示例:
我在自己的项目中使用它.proxy.example:
export http_proxy=http://username:userpassword@server.company:port
export https_proxy=http://username:userpassword@server.company:port
export no_proxy=.company localhost
Run Code Online (Sandbox Code Playgroud)
thd*_*oan 15
我喜欢做的是设置两个Git别名:
〜/的.gitconfig
[alias]
noproxy = config --global --remove-section http
proxy = config --global http.proxy http://127.0.0.1:9666
Run Code Online (Sandbox Code Playgroud)
请注意,我没有使用config --global --unset http.proxy重置代理,因为它留下了[http]部分标题,因此在重复启用和禁用代理之后,您.gitconfig将被一堆空的[http]章节标题污染.没什么大不了的,但这只是烦人的.
在某些情况下,例如在企业防火墙后面,您需要进行配置~/.ssh/config.设置变得稍微复杂一些:
〜/的.gitconfig
[alias]
noproxy = !sh -c 'cp ~/.ssh/config.noproxy ~/.ssh/config'
proxy = !sh -c 'cp ~/.ssh/config.proxy ~/.ssh/config'
Run Code Online (Sandbox Code Playgroud)
的〜/ .ssh/config.noproxy
Host github.com-username
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
Run Code Online (Sandbox Code Playgroud)
的〜/ .ssh/config.proxy
Host *
ProxyCommand connect -H 127.0.0.1:9666 %h %p
Host github.com-username
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
Run Code Online (Sandbox Code Playgroud)
您甚至可以通过将别名更改为以下两种方法来组合:
[alias]
noproxy = !sh -c 'git config --global --remove-section http 2> /dev/null && cp ~/.ssh/config.noproxy ~/.ssh/config'
proxy = !sh -c 'git config --global http.proxy http://127.0.0.1:9666 && cp ~/.ssh/config.proxy ~/.ssh/config'
Run Code Online (Sandbox Code Playgroud)
现在我只需键入git noproxy即可禁用代理并git proxy启用它.您甚至可以通过创建更多别名来切换多个代理.
| 归档时间: |
|
| 查看次数: |
19881 次 |
| 最近记录: |