无法读取“https://github.com”的用户名:Windows 上禁用终端提示

cri*_*id9 3 git go

我试图使用私有存储库获取一些依赖项go get -u <github_private_repo_link>,但它一直失败并出现以下错误:

server response:
not found: github.com/..../v3@v3.11.1: invalid version: git ls-remote -q origin in /tmp/gopath/pkg/mod/cache/vcs/168bff8af96cdfac9cbe3ad64f7753732f8a19d99f7f1e897f19371e1ea453d9: exit status 128:
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.
Run Code Online (Sandbox Code Playgroud)

我尝试导出set GIT_TERMINAL_PROMPT=1,但没有任何反应,出现同样的错误。有什么办法 go get 会忽略 Windows 上这个变量的值吗go 1.13

jes*_*ing 6

尝试为 GitHub 设置临时凭证处理程序:

GIT_USER="your-github-username-or-email"
GIT_PASS="PAT"

git config --global credential.helper "!f() { echo \`"username=`${GIT_USER}`npassword=`${GIT_PASS}\`"; }; f"
Run Code Online (Sandbox Code Playgroud)

或者安装 github cli 并使用 进行身份验证到 github gh auth login

查看错误消息中提到的文档以了解其他选项

可以将 Git 配置为通过 HTTPS 进行身份验证或使用 SSH 代替 HTTPS。$HOME/.netrc要通过 HTTPS 进行身份验证,您可以向 git 查阅的文件添加一行:

machine github.com login USERNAME password APIKEY
Run Code Online (Sandbox Code Playgroud)

对于 GitHub 帐户,密码可以是个人访问令牌。

Git 还可以配置为使用 SSH 代替 HTTPS 来处理与给定前缀匹配的 URL。例如,要使用 SSH 进行所有 GitHub 访问,请将这些行添加到您的~/.gitconfig

[url "ssh://git@github.com/"]
    insteadOf = https://github.com/
Run Code Online (Sandbox Code Playgroud)