git - 使用代理获取私有(private)仓库

标签 git go go-modules go-get

我公司提供了VPN,但是只是全局代理,所以我在docker里启动了一个vpn,对外提供了sock5代理,我想要go get ≈ <private_repo_path>使用我本地启动的 sock5 代理。

我的配置文件

- Go env
``` 
GOPRIVATE="<company_gitlab_url>"
GOPROXY="http://goproxy.cn,direct" (I'm in China. This is CN Golang Proxy)
```
- Git
```
[http "https://<company_gitlab_url>"]
    proxy = socks5://127.0.0.1:1080
    
[url "ssh://git@<company_gitlab_url>"]
        insteadOf = http://<company_gitlab_url>/

[url "git@<company_gitlab_url>:"]
        insteadOf = http://<company_gitlab_url>/
```    
- netrc
```
machine <company_gitlab_url>
  login username
  password accessToken
```

我期待 git clone <company_gitlab>/<repo_name>命令使用sock5代理,所以我已经为git配置了http代理,它可以工作

[http "https://<company_gitlab_url>"]
        proxy = socks5://127.0.0.1:1080

但是go get <company_gitlab>/<repo_name>不起作用(不使用sock5代理)

知道go get本质上是 git clone我有ssh insteadOf http设置完毕后,我想我应该配置一个 SSH 代理:

所以我将以下配置添加到.ssh/config

Host <company_gitlab_url>
    ProxyCommand nc -X 5 -x 127.0.0.1:1080 %h %p

但是没用

go get <company_gitlab_url>/<repo_name>显示

go get: unrecognized import path "<company_gitlab_url>/golang/base": https fetch: Get "https://<company_gitlab_url>/golang/base?go-get=1": dial tcp 10.130.xxx .xxx:443: i/o timeout

我认为 10.130.xxx.xxx 是我公司 Gitlab.net 的内部 IP,我该怎么办?

最佳答案

我修复了,go get xx不仅使用ssh,而且有一次http fetch。

所以使用https_proxy(http_proxy)=sock5://xxx go get xxx命令

关于git - 使用代理获取私有(private)仓库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73593896/

相关文章:

unicode - 连接 net.Addr 和 []rune

generics - 在go中获取不同属性的通用函数

go - VSCODE 无法在 go 模块中安装工具

git - FETCH_HEAD 引用在 "git fetch"之后未正确更新

Git 在 git pull 和询问密码之间有很长的延迟

git - 'cherry' 在 git-cherry 中意味着什么?

go - 在 golang 中将 [][]byte 转换为 []string 的最有效方法

go - go 如何知道从哪里获取包

go - 如何强制 go mod 接受声明其路径与其 go.mod 不同的模块?

git - 如何在我的终端中缩短它?