-1

I use the following command to set the proxy

$ 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

But when I clone a repo, such as

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

It doesn't use the proxy to clone.

I try to change my proxy address, it is random address.

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

If the proxy work, git should prompt some error. But when I clone again,it didn't prompt any error

$ 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

That mean the git proxy does'nt work.

I also tried to use the environment variable

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

But it still not work.

s97712
  • 455
  • 1
  • 4
  • 14

2 Answers2

2
git clone git@github.com:…

This is SSH protocol (scp-like URL syntax), it doesn't use HTTP proxy. To use proxy change the URL to HTTPS:

git clone https://github.com:…

PS. Port 1080 suggests that it's a SOCKS proxy, not an HTTP proxy. If it's I think the proxy syntax is different. See https://stackoverflow.com/a/16756248/7976758 and https://stackoverflow.com/search?q=%5Bgit%5D+socks+proxy.

phd
  • 82,685
  • 13
  • 120
  • 165
  • `git config --global git.proxy http://127.0.0.1:1080` can't work in `git@github.com:..` ? my proxy address 'http ://127.0.0.1:1080' can work on wget or curl, but can't work on git. – s97712 Aug 28 '19 at 08:54
  • `wget` and `curl` use HTTP protocol, `git clone git@github.com:…` uses SSH protocol and SSH protocol doesn't use HTTP proxy, understand? To use proxy change the URL to HTTPs. – phd Aug 28 '19 at 08:56
0

I proxy my connections to github.com over a socks5 (ssh) proxy.

i.e. ssh -C -D 1080 user@host -f -N (ssh socks5 proxy through host in the background with no default command and compression enabled). My ~/.ssh/config for github.com looks like:

Host github.com
    ProxyCommand /bin/nc -X 5 -x 127.0.0.1:1080 %h %p
masseyb
  • 3,745
  • 1
  • 17
  • 29