无法将代码推送到项目 - 错误 403

Can not push code to the project - error 403

我在尝试将代码推送到项目时遇到问题。 Git 显示错误信息:

Push failed
Remote: You are not allowed to push code to this project.
unable to access 'https://gitlab.name.com/project/repo.git/': The requested URL returned error: 403
    

我有权访问存储库,我的 SSH 密钥没有过期(我还创建了一个新密钥)。我不能推送,但我可以从项目中获取代码。不知道发生了什么。 我用的是Androd Studio。

看起来您正在使用 https 而不是 ssh 推送到您的存储库,因此没有使用您的 ssh 密钥。

更改远程存储库 URL 的一些步骤:

git remote -v
# Should see
# origin   https://gitlab.name.com/project/repo.git (fetch)
# origin   https://gitlab.name.com/project/repo.git (push)

git remote set-url origin git@gitlab.name.com:project/repo.git
# you should be able to get the SSH url from the GitLab UI if in doubt

git remote -v
# verify changes
# origin   git@gitlab.name.com:project/repo.git (fetch)
# origin   git@gitlab.name.com:project/repo.git (push)

I've change https to ssh as you wrote but there is another error message:

Push failed Remote: You are not allowed to push code to this project Could not read from remote repository.

在 command-line 中测试您的 SSH 身份验证:

ssh -Tv git@gitlab.name.com

您将检查是否确实考虑了您的新 SSH 密钥。

您需要将自己添加为项目成员。