收到致命错误:无法读取“https://github.com”的用户名:在终端中构建项目时终端提示已禁用

Joy*_*Joy 12 git

我已经开始从事 Golang 项目。使用 make 构建时,出现以下错误:

fatal: could not read Username for 'https://github.com': terminal prompts disabled
Run Code Online (Sandbox Code Playgroud)

为了解决这个问题,我在通过类似的帖子go get results in 'terminal prompts disabled' error for github private repo后做了以下工作:

export GIT_TERMINAL_PROMPT=1
Run Code Online (Sandbox Code Playgroud)

但这并没有解决问题,现在它似乎在无限循环中询问用户名和密码。

我的git配置如下:

$git config --list

remote.origin.url=git@github.com:GolangProjects/Project1.git
Run Code Online (Sandbox Code Playgroud)

即使在这个配置之后,为什么它继续使用 https 而不是 SSH,没有得到任何线索。请帮忙。

Him*_*shu 18

而是创建一个 SSH 密钥,并将其用作 git repo 的默认登录方法。您可以按照此链接在您的机器上创建用于身份验证的 ssh 密钥:

生成新的 SSH 密钥并将其添加到 ssh-agent

然后使用它来默认您的登录方法使用 ssh 密钥而不是您的凭据:

git config --global url.ssh://git@github.com/.insteadOf https://github.com/
Run Code Online (Sandbox Code Playgroud)

  • 对 Mac/iOS 开发人员的警告 - 上面的全局 git 配置将修复命令行上的问题,但会破坏 Xcode 中的 Git。 (2认同)