'Access GitLab repo with project access token

According to the documentation, it should be possible to access GitLab repos with project access tokens:

The username is set to project_{project_id}_bot, such as project_123_bot.

Never mind that that's a lie -- the actual user is called project_4194_bot1 in my case; apparently they increment a number for subsequent tokens.

Either way -- and I have tried both with and without the trailing 1 -- I would expect

git clone "https://project_4194_bot1:[email protected]/my-group/my-project.git"

to succeed, same as with my.username:$PERSONAL_TOKEN (which works perfectly). However, I get

remote: HTTP Basic: Access denied
fatal: Authentication failed for '<snip>'

What may be going on here? How can I access GitLab repositories using project access tokens?


It's not as if we'd get that far, but FWIW, the token seems to have sufficient permissions:

enter image description here



Solution 1:[1]

It seems that using the project name as username works. In your case replacing project_4194_bot1 with my-project should work:

git clone "https://my-project:[email protected]/my-group/my-project.git"

Solution 2:[2]

I've found that depending on the git version The 'user' can be left empty or a random string if the token is a project access token.

git clone "https://<$USER>:[email protected]/my-group/my-project.git"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rafael-WO
Solution 2