简体   繁体   English

无法在 github 操作中运行 git 克隆

[英]Unable to run git clone in github actions

I setup my password and username as follow:我设置我的密码和用户名如下:

git config --global user.email $git_email
git config --global user.name $git_username
git config --global user.password $git_password

where $git_email, $git_username, and $git_password point to the correct environmental variables.其中 $git_email、$git_username 和 $git_password 指向正确的环境变量。

Now when I try to run git clone I get the following error: 
Cloning into 'certificates'...
fatal: could not read Username for 'https://github.com': Device not configured

The same approach works locally and in Travis CI so I'm not sure what the issue is.同样的方法在本地和 Travis CI 中都有效,所以我不确定问题出在哪里。

user.name is not a username, and user.password does not exist. user.name不是用户名, user.password不存在。 From the documentation for user.name :user.name文档中:

Note that the name forms of these variables conventionally refer to some form of a personal name.请注意,这些变量的名称 forms 通常指的是某种形式的个人姓名。 See git-commit(1) and the environment variables section of git(1) for more information on these settings and the credential.username option if you're looking for authentication credentials instead.有关这些设置和credential.username选项的更多信息,请参阅 git-commit(1) 和 git(1) 的环境变量部分(如果您正在寻找身份验证凭据)。

That is, user.name should be your (human) name, not a username.也就是说, user.name应该是您的(人)名,而不是用户名。

As a result, you're being prompted for a username and password, but you're getting a failure because there's no TTY on which to prompt you.结果,系统提示您输入用户名和密码,但您遇到了失败,因为没有 TTY 可以提示您。 On your system, the credentials are probably already saved in your credential helper, which is why you're not seeing the prompt.在您的系统上,凭据可能已经保存在您的凭据助手中,这就是您看不到提示的原因。

If you want to clone another repository, you should first create a personal access token and store that in your CI system's secret storage (eg, as an environment variable called TOKEN ).如果你想克隆另一个存储库,你应该首先创建一个个人访问令牌并将其存储在你的 CI 系统的秘密存储中(例如,作为一个名为TOKEN的环境变量)。 PATs don't change when your password does, can be revoked and rotated independent of your password, and are more secure than most passwords. PAT 不会在您的密码更改时更改,可以独立于您的密码被撤销和轮换,并且比大多数密码更安全。

Then, in your CI tool, run the following:然后,在您的 CI 工具中,运行以下命令:

$ git config credential.helper '!f(){echo username=token; echo "password=$TOKEN";};f'

This will set up a credential helper to use the token that's in the TOKEN environment variable as your password.这将设置一个凭证助手,以使用TOKEN环境变量中的令牌作为您的密码。 Make sure that environment variable is set for your clone operation, and things should just work.确保为您的克隆操作设置了环境变量,并且一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM