Gangmax Blog

自由之思想,独立之精神

GitLab Personal Access Token

From here, here, and here.

After I enabled the “two-factor authentication“ on GitLab, I got the following error message when pushing changes to the remote Git repo:

1
remote: HTTP Basic: Access denied
2
remote: You must use a personal access token with 'read_repository' or 'write_repository' scope for Git over HTTP.
3
remote: You can generate one at https://gitlab.com/profile/personal_access_tokens
4
fatal: Authentication failed for 'https://gitlab.com/user/project.git/'

After some research I realize some changes should be done to make it work.

First, you need to create an access token with the “read_repository/write_repository” permissions in GitLab. Then add the token into your remote repo’s HTTPS URL as below:

1
# 1. Remove the remote item first.
2
git remote remove origin
3
# 2. Add it again with the token.
4
git remote add origin https://oauth2:ThIsiStHeToKeNcOnTeNt@gitlab.com/user/project.git
5
# 3. Set upstream branch.
6
git branch --set-upstream-to=origin/master master

After that, I can push the changes successfully without “username/password” required.

Comments