Git get 私有仓库报错
当安装一个私有库的时候,会报错,比如
go: gitlab.xgjoy.org/demo/demo@latest: module gitlab.xgjoy.org/demo/demo: git ls-remote -q origin in /home/user00/go/pkg/mod/cache/vcs/: exit status 128:
fatal: could not read Username for 'https://gitlab.xgjoy.org': terminal prompts disabled
Confirm the import path was entered correctly.
If this is a private repository, see https://golang.org/doc/faq#git_https for additional information.
这是因为,go get 请求仓库是,默认采用 https 的方式,即使本地添加了 gitlab 的 ssh 的免密,还是 https 方式还是无授权的,因此,有以下解决方案:
- 将 https 转为 ssh 方式
git config --global url."ssh://[email protected]".insteadOf https://gitlab.xgjoy.org
或在~/.gitconfig 中添加下列数据
[url "ssh://[email protected]"]
insteadOf = https://gitlab.xgjoy.org
- HTTPS 增加授权
git config --global url."https://gitlab-ci-token:[email protected]".insteadOf https://gitlab.xgjoy.org
这个 token 可以从 gitlab 上申请一个只读的 token
或在~/.gitconfig 中添加下列数据
[url "https://gitlab-ci-token:[email protected]"]
insteadOf = https://gitlab.xgjoy.org