当我们使用go.mod
拉取私有仓库代码时,会报一下错误
fatal: could not read Username for 'https://github.com': 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.
若是我们使用的是密钥方式获取的,只需要设置获取模式即可,因为此时拉取代码的方式是 https
, 我们修改成 ssh
方式即可
修改本地 .gitconfig
文件
vim ~/.gitconfig
# 添加信息
[url "ssh://git@github.com/"]
insteadOf=https://github.com/
修改后再使用 go mod download
或者 go mod tidy
就可以正常下载文件了