You need to use a personal access token to clone your repository from GitLab when Two Factor authentication is enabled. Which explained here.
Follow @AbhithRajanAbhith RajanDecember 19, 2018 · 2 min read · Last Updated:
I love services which provide extra security. One way to provide such a level security is by using Two Factor Authentication (2FA). GitLab provides 2FA, and I enabled it. After that, cloning a repository will not work in the usual mode,
git clone https://gitlab.com/username/projectname.git
It will result
Cloning into 'projectname'...remote: HTTP Basic: Access deniedremote: You must use a personal access token with 'api' scope for Git over HTTP.remote: You can generate one at https://gitlab.com/profile/personal_access_tokensfatal: Authentication failed for 'https://gitlab.com/username/projectname.git/'
As the response suggest, we need to create a personal access token.
Creating a personal access token
- Log in to your GitLab account.
- Go to your Profile settings.
- Go to Access tokens.
- Choose a name and optionally an expiry date for the token.
- Choose the desired scopes (api access).
- Click on Create personal access token.
- Save the personal access token somewhere safe. Once you leave or refresh the page, you won’t be able to access it again.
Once you have created your personal access token, try cloning by
git clone https://oauth2:[email protected]/username/projectname.git
Replace ‘PERSONAL_ACCESS_TOKEN’ with the token you have generated.
Additional Resources
This page is open source. Noticed a typo? Or something unclear?
Improve this page on GitHub
Written byAbhith Rajan Follow @AbhithRajan
Abhith Rajan is a software engineer by day and a full-stack developer by night. He's coding for almost a decade now. He codes 🧑💻, write ✍️, learn 📖 and advocate 👍.
Connect
Is this page helpful?
Related StoriesView All
Related Tools & ServicesView All
rtyley.github.io
BFG Repo-Cleaner by rtyley
A simpler, faster alternative to git-filter-branch for deleting big files and removing passwords from Git history.
toptal.com
gitignore.io
Create useful .gitignore files for your project by selecting from 509 Operating System, IDE, and Programming Language .gitignore templates