当前位置:   article > 正文

Go Module 私有仓库:fatal: could not read Username for ‘https://xxx.com‘: terminal prompts disabled_invalid version: git ls-remote -q origin

invalid version: git ls-remote -q origin
说明

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

错误信息
go get: gitee.com/xxxxx/proto@v1.0.0: reading https://goproxy.cn/gitee.com/xxxxxr/proto/@v/v1.0.1.info: 404 Not Found
        server response:
        not found: gitee.com/xxxx/proto@v1.0.1: 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.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
设置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	 }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

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

https替换成ssh

需要在仓库绑定SSH公钥

git config --global url."git@xxx.com:".insteadOf "https://xxx.com/"
  • 1

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

设置 GOPRIVATE

通过GOPRIVATE来指定你的仓库

go env -w GOPRIVATE=xxx.com/xxx
  • 1
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/680930
推荐阅读
相关标签
  

闽ICP备14008679号