通过git拉代码,或者拉内部依赖仓库包时报错,报错信息如下
root@fer:/srv/go_project/demo# go get www.baidu.com/pkg
go: module www.baidu.com/pkg: git ls-remote -q origin in /root/go/pkg/mod/cache/vcs/3f7462beb28a6d3aa637bf1b9891bde68233a7ee245ee05db64d1bb3b11a6fd7: exit status 128:
fatal: could not read Username for 'https://www.baidu.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.
原因,凭证无效,解决方法重新生成凭证
ubuntu
.gitconfig文件示例
[user] name = fer email = fer@baidu.com [credential] helper = store [core] editor = vim autocrlf = input
1.确保git凭证方式credential与上述一致
2.export GIT_TERMINAL_PROMPT=1
3. 重新执行 go get www.baidu.com/pkg 会提示输入用户名密码,然后就会自动刷新凭证,生成凭证文件.git-credentials 在root目录下 文件内容 https://用户名:密码@www.baidu.com
如果上述方式不行,也可以手动新增凭证文件.git-credentials 按上述内容格式新增,然后重新拉取
Windows
1.gitlab上新增token凭证
2.windows凭证中添加后,重新拉取