git - 无法在 github 操作中运行 git clone
问题描述
我设置我的密码和用户名如下:
git config --global user.email $git_email
git config --global user.name $git_username
git config --global user.password $git_password
其中 $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
同样的方法在本地和 Travis CI 中有效,所以我不确定问题是什么。
解决方案
user.name
不是用户名,user.password
也不存在。从文档中user.name
:
请注意,这些变量的名称形式通常指的是某种形式的个人姓名。有关这些设置和选项的更多信息,请参阅 git-commit(1) 和 git(1) 的环境变量部分,
credential.username
如果您正在寻找身份验证凭据。
也就是说,user.name
应该是您的(人)名,而不是用户名。
结果,系统会提示您输入用户名和密码,但您会失败,因为没有 TTY 可以提示您。在您的系统上,凭据可能已经保存在您的凭据助手中,这就是您没有看到提示的原因。
如果您想克隆另一个存储库,您应该首先创建一个个人访问令牌并将其存储在您的 CI 系统的秘密存储中(例如,作为名为 的环境变量TOKEN
)。PAT 在您的密码发生变化时不会更改,可以独立于您的密码撤销和轮换,并且比大多数密码更安全。
然后,在您的 CI 工具中,运行以下命令:
$ git config credential.helper '!f(){echo username=token; echo "password=$TOKEN";};f'
这将设置一个凭证助手以使用TOKEN
环境变量中的令牌作为您的密码。确保为您的克隆操作设置了环境变量,并且一切正常。
推荐阅读
- python-2.7 - 有更好的方法来定位二进制图像上的空格吗?
- java - 如何创建一个使用给定名称和“给定电话列表”初始化联系信息的构造函数
- javascript - Node js express session - 后退按钮问题(但在移动设备上)
- r - 了解'| ' 和 ' & ' 运算符行为(R 的逻辑运算符)
- python - AttributeError: 'scoped_session' 对象没有属性 'session'
- python - 如何将外部函数类传递给内部类?
- werkzeug - safe_string_cmp 的目的是什么?
- vb.net - 在最小化窗口中获取鼠标点击坐标
- c - 在链接聚合方案中禁用 IP 重组/碎片整理
- python - 在子目录中实例化类时遇到问题