【问题标题】:Why my git proxy config does not work? I'm sure I've set it up correctly, but it still doesn't work为什么我的 git 代理配置不起作用?我确定我已正确设置它,但它仍然无法正常工作
【发布时间】:2020-01-01 09:45:33
【问题描述】:

我使用以下命令设置代理

$ git config --global git.proxy http://127.0.0.1:1080
$ git config --global http.proxy http://127.0.0.1:1080
$ git config --global https.proxy http://127.0.0.1:1080

但是当我克隆一个 repo 时,比如

# git clone git@github.com:npm/npm.git

不使用代理进行克隆。

我尝试更改我的代理地址,它是随机地址。

$ git config --global git.proxy asdfi:sidfw:sfd
$ git config --global http.proxy asdfi:sidfw:sfd
$ git config --global https.proxy asdfi:sidfw:sfd

如果代理工作,git 应该会提示一些错误。 但是当我再次克隆时,它没有提示任何错误

$ git clone git@github.com:s97712/protobuf.js.git
Cloning into 'protobuf.js'...
Enter passphrase for key '/home/s97712/.ssh/id_rsa': 
remote: Enumerating objects: 1, done.
remote: Counting objects: 100% (1/1), done.
Receiving objects:   2% (363/18110), 60.00 KiB | 5.00 KiB/s

这意味着 git 代理不起作用。

我也试过使用环境变量

$ export http_proxy="http://localhost:1080"
$ export https_proxy="http://localhost:1080"

但还是不行。

【问题讨论】:

    标签: git proxy


    【解决方案1】:
    git clone git@github.com:…
    

    这是 SSH 协议(类似 scp 的 URL 语法),它不使用 HTTP 代理。要使用代理,请将 URL 更改为 HTTPS:

    git clone https://github.com:…
    

    PS。端口 1080 表明它是 SOCKS 代理,而不是 HTTP 代理。如果是我认为代理语法不同。请参阅https://stackoverflow.com/a/16756248/7976758 和https://stackoverflow.com/search?q=%5Bgit%5D+socks+proxy。

    【讨论】:

    • git config --global git.proxy http://127.0.0.1:1080 不能在git@github.com:.. 中工作?我的代理地址 'http://127.0.0.1:1080' 可以在 wget 或 curl 上工作,但不能在 git 上工作。
    • wget 和 curl 使用 HTTP 协议,git clone git@github.com:… 使用 SSH 协议,而 SSH 协议不使用 HTTP 代理,明白吗?要使用代理,请将 URL 更改为 HTTPS。
    【解决方案2】:

    我通过 socks5 (ssh) 代理代理我与 github.com 的连接。

    即ssh -C -D 1080 user@host -f -N(ssh socks5 在后台通过主机代理,未启用默认命令和压缩)。我的 github.com 的 ~/.ssh/config 看起来像:

    Host github.com
        ProxyCommand /bin/nc -X 5 -x 127.0.0.1:1080 %h %p
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-20
      相关资源
      最近更新 更多