gitlab | git

GitLab - Clone a repository when 2FA enabled

You need to use a personal access token to clone your repository from GitLab when Two Factor authentication is enabled. Which explained here.

Abhith 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,

1git clone https://gitlab.com/username/projectname.git

It will result

1Cloning into 'projectname'...
2remote: HTTP Basic: Access denied
3remote: You must use a personal access token with 'api' scope for Git over HTTP.
4remote: You can generate one at https://gitlab.com/profile/personal_access_tokens
5fatal: 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

  1. Log in to your GitLab account.
  2. Go to your Profile settings.
  3. Go to Access tokens.
  4. Choose a name and optionally an expiry date for the token.
  5. Choose the desired scopes (api access).
  6. Click on Create personal access token.
  7. 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

1git clone https://oauth2:PERSONAL_ACCESS_TOKEN@gitlab.com/username/projectname.git

Replace ‘PERSONAL_ACCESS_TOKEN’ with the token you have generated.

Additional Resources

Written by Abhith Rajan
Abhith Rajan is an aspiring software engineer with more than 8 years of experience and proven successful track record of delivering technology-based products and services.
Buy me a coffee

Was this helpful?

👈 This is a live react editor.

This page is open source. Noticed a typo? Or something unclear?
Improve this page on GitHub

Related VideosView All

Git MERGE vs REBASE

Related StoriesView All

Related Tools & ServicesView All

toptal.com

gitignore.io

Create useful .gitignore files for your project by selecting from 509 Operating System, IDE, and Programming Language .gitignore templates