gpt4 book ai didi

git - 开启gitlab二次验证后如何使用git命令

转载 作者:IT王子 更新时间:2023-10-29 01:30:27 28 4
gpt4 key购买 nike

今天我启用了 Gitlab 的第二因素身份验证。之后,因为我登录了Gitlab网站,我需要用我的手机传递一个6位数字加上我的密码,这样很好,让我感到安全。

但是,当我使用一般操作时,例如git clone some-repo.git,我得到了错误:

Cloning into 'some-repo'...
remote: HTTP Basic: Access denied
remote: You must use a personal access token with 'api' scope for Git over HTTP.
remote: You can generate one at https://gitlab.com/profile/personal_access_tokens
fatal: Authentication failed for 'some-repo.git'

然后我尝试使用 git pull 现有克隆的本地 repo,出现同样的错误。在启用第二因素身份验证之前,上述所有操作都运行良好。

按照上面的错误提示,我去了上面提到的地址:https://gitlab.com/profile/personal_access_tokens .我创建了以下 token ,并保存了 token 的 key 。

enter image description here

但是,我不知道如何使用这把 key 。谁能告诉我如何使用此 key 启用基本操作,如 git pullgit clonegit push 等...

编辑

在启用第二因素身份验证之前,我在本地有很多 repo 协议(protocol)。我也希望这些能起作用。

最佳答案

using gitlab token to clone without authentication 中所述,您可以像这样使用您的个人访问 token 克隆 GitLab 存储库:

git clone https://oauth2:ACCESS_TOKEN@gitlab.com/yourself/yourproject.git

至于如何更新现有克隆以使用 GitLab Personal Access Token,您应该在每个本地 git 目录中编辑 .git/config 文件,该文件将包含如下条目:

[remote "origin"]
url = https://yourself@gitlab.com/yourself/yourproject.git

更改url:

[remote "origin"]
url = https://oauth2:ACCESS_TOKEN@gitlab.com/yourself/yourproject.git

现在您可以像启用 2FA 之前一样继续使用这个现有的 git 克隆。

关于git - 开启gitlab二次验证后如何使用git命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51658549/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com