不像这篇文章,我使用的是macOS。

我已经在GitLab中配置了密码。我也有一个SSL密钥创建后的项目是在GitLab。

当我在新项目中使用现有文件夹并执行以下步骤时,系统会提示我输入GitLab用户名和密码。

现有的文件夹

cd existing_folder
git init
git remote add origin https://gitlab.com/sobopla/Geronimod.git
git add .
git commit -m "Initial commit"
git push -u origin master

输入密码后,我得到以下错误。

remote: HTTP Basic:拒绝访问 致命:“https://gitlab.com/myname/myproject”认证失败


当前回答

这当然是一个错误,ssh在我的一台机器上工作,但在另一台机器上不工作。我解出来了,跟着这些。

生成一个永不过期的访问令牌,并选择所有可用选项。 删除已有的SSH密钥。 用https而不是ssh克隆repo。 使用用户名,但使用生成的访问令牌,而不是密码。

或者,您可以在现有的repo中使用此命令将remote设置为HTTP,并使用此命令git remote set-url origin https://gitlab.com/[username]/[repo-name].git

其他回答

仅供参考,我在生成并粘贴ssh_rsa后错误地使用URL时遇到了这个问题。pub到gitlab中的SSH密钥。

$ git clone http://gitlab.x
Cloning into 'start-up'...
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 http://gitlab.x

通过使用下面的URL来解决。

$ git clone gitlab@gitlab.xxx.com/your_project.git

以上的解决方案都不适合我,而且我没有笔记本电脑的管理权限,但它们最终引导我找到了git工具凭据存储文档:

我的设置 Windows 10 | Git 2.18.0.windows。1 | 通过HTTPS链接克隆

如果你使用wincred作为凭据帮助器,这个解决方案是有效的:

> git config --global credential.helper
wincred

将助手更改为“缓存”应该可以达到目的,因为它会要求您再次提供凭据。要将其设置为缓存,只需输入:

> git config --global credential.helper cache

检查您的更新是否激活:

> git config --global credential.helper
cache

您现在应该能够像以前一样克隆/提取/获取。

这个方法在Windows和Mac上都适用:

https://Username:accessToken@git.gitlab.com/path/to/repo/my-app.git

这里accessToken是在GitLab中创建的个人访问令牌。

每当我被迫修改Windows密码时,上面的答案都帮不了我。

试试下面对我有用的解决方案:

进入Windows凭证管理器。这是通过在EN-US Windows中按下Windows键并输入“credential”来完成的。在其他 本地化的Windows变体,您需要使用本地化术语(请参阅 一些例子的注释)。 您也可以使用快捷方式 control /name微软。运行对话框中的CredentialManager (WIN + R) 编辑Windows凭证下的git条目,替换旧的 用新密码。

奇怪的是,对我有效的方法是退出并重新登录到GitLab web UI。

我完全不知道为什么会这样。