2013-10-22 50 views
14

我在企業防火牆後面使用git,並且使用http.proxy --global配置成功克隆了外部項目。如何暫時禁用git http代理

我想通過內部網上的http進行克隆時出現問題。我懷疑代理配置會干擾Intranet請求。

我知道我可以在使用內部網之前重置配置,但這不是非常用戶友好的。

我也看到這個answer,但它似乎只適用於現有的存儲庫。

是否有一種方法可以僅對一個命令調用停用代理使用情況?在這種情況下,最初的克隆?

回答

27

我總是設置:

no_proxy=.mycompany 

export如果我在Unix或簡單set在Windows上)

這足以繞過代理與「.mycompany」結尾的所有內部網網址。

見一個例子:

我用它在我自己的項目:.proxy.example

export http_proxy=http://username:[email protected]:port 
export https_proxy=http://username:[email protected]:port 
export no_proxy=.company localhost 
+0

我希望我可以多次投票!我花了好幾天的時間試圖想出這件該死的東西!謝謝你,兄弟! –

+0

非常感謝你......這讓我瘋狂...... – Tracker1

9

我喜歡做的是設置兩個混帳別名:

〜/我沒有使用config --global --unset http.proxy因爲離開[http]節標題後面重置代理的.gitconfig

[alias] 
     noproxy = config --global --remove-section http 
     proxy = config --global http.proxy http://127.0.0.1:9666 

注,所以在重複啓用和禁用代理後,您的.gitconfig將被一些空的[http]節標題污染。沒什麼大不了的,但它只是令人討厭。


在某些情況下,如企業防火牆後面,你需要配置~/.ssh/config代替。安裝變得稍微複雜一些:

〜/的.gitconfig

[alias] 
     noproxy = !sh -c 'cp ~/.ssh/config.noproxy ~/.ssh/config' 
     proxy = !sh -c 'cp ~/.ssh/config.proxy ~/.ssh/config' 

的〜/ .ssh/config.noproxy

Host github.com-username 
    HostName github.com 
    User git 
    IdentityFile ~/.ssh/id_rsa 

的〜/ .ssh /配置。代理

Host * 
    ProxyCommand connect -H 127.0.0.1:9666 %h %p 

Host github.com-username 
    HostName github.com 
    User git 
    IdentityFile ~/.ssh/id_rsa 

你甚至可以在兩種方法通過改變別名到這個結合:

[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' 

現在,我可以簡單地輸入git noproxy禁用代理和git proxy啓用它。您甚至可以通過創建更多別名在多個代理之間切換。