不像这篇文章,我使用的是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”认证失败


当前回答

您必须使用当前访问令牌更新.git目录中的配置文件。 请参阅此链接,我解决了因意外更改访问令牌而引起的问题。我在用GITLAB和CLion,

其他回答

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

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

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

在Gitlab中,进入管理员/设置/常规/登录限制部分。

如果您正在通过HTTPS对GitLab进行身份验证,请确保您具备:

Allow password authentication for Git over HTTP(S)

检查。此选项假设您不使用2FA。如果您不使用外部身份验证提供程序,则显示还具有:

Allow password authentication for the web interface

也检查。

您可以尝试以下命令:

git config --system --unset credential.helper

然后,输入Git远程服务器的新密码。

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

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

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

唯一对我有用的是使用https://username:Password@gitlab.com/user/projectgit而不是https://gitlab.com/user/projectgit。参见https://gitlab.com/gitlab-com/support-forum/issues/1654