I've recently started to enable
2FA
(Two Factor Authentication) on most of my online accounts, including
GitLab
. But what happen when you try to
clone
a repository against https after that?
When I tried the first time I run the usual git clone:
git clone https://gitlab.com/username/project.git
Cloning into 'mypersonalbalance'...
remote: HTTP Basic: Access denied
remote: You must use a personal access token with 'read_repository' or 'write_repository' scope for Git over HTTP.
remote: You can generate one at https://gitlab.com/profile/personal_access_tokens
fatal: Authentication failed for 'https://gitlab.com/f.peluso/mypersonalbalance.git/'
Enter fullscreen modeExit fullscreen mode
I googled a little bit, finding that the problems was the 2 factor authentication, and then I found the following solution:
Log in into the GitLab account;
Go to the Settings section (at the moment, top right, hover the profile image and wait for the menu);
Go to Access Tokens;
Now here you can create a temporary token; if you need to pull/push you must enable read_repository and write_repository flags.
A token is shown in the page. Don't close or refresh the page, or you won't be able to retrieve the same token again!!!
Save the token somewhere safe if you need to use it more than once (I needed only once, so I just copypasted it, and then deleted it).
After these steps you can clone the repository using
git clone https://oauth2:[email protected]/username/project.git
Enter fullscreen modeExit fullscreen mode
Built on Forem — the open source software that powers DEV and other inclusive communities.