Go Module 私有仓库:fatal: could not read Username for ‘https://xxx.com‘: terminal prompts disabled

说明

关于Go Module拉取私有仓库时,遇到terminal prompts disabled权限的问题。

错误信息

go get: gitee.com/xxxxx/[email protected]: reading https://goproxy.cn/gitee.com/xxxxxr/proto/@v/v1.0.1.info: 404 Not Found
        server response:
        not found: gitee.com/xxxx/[email protected]: invalid version: git ls-remote -q origin in /tmp/gopath/pkg/mod/cache/vcs/38e9fe3a96fe68d3df32046929625c624d2613d5084f9e174c10834d6791c202: exit status 128:
                fatal: could not read Username for 'https://gitee.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.

设置GIT_TERMINAL_PROMPT

在go get源码包中有以下一段代码:

90	 // Disable any prompting for passwords by Git.
91	 // Only has an effect for 2.3.0 or later, but avoiding
92	 // the prompt in earlier versions is just too hard.
93	 // If user has explicitly set GIT_TERMINAL_PROMPT=1, keep
94	 // prompting.
95	 // See golang.org/issue/9341 and golang.org/issue/12706.
96	 if os.Getenv("GIT_TERMINAL_PROMPT") == "" {
97	 	 os.Setenv("GIT_TERMINAL_PROMPT", "0")
98	 }

可以通过设置环境变量GIT_TERMINAL_PROMPT = 1 来开启账号密码的验证。

https替换成ssh

需要在仓库绑定SSH公钥

git config --global url."[email protected]:".insteadOf "https://xxx.com/"

配置仓库的全局选项将https替代成ssh

设置 GOPRIVATE

通过GOPRIVATE来指定你的仓库

go env -w GOPRIVATE=xxx.com/xxx

你可能感兴趣的:(Go,git,golang,go,gomod)