How to use git commands after enable gitlab's second-factor authentication

As explained in using gitlab token to clone without authentication, you can clone a GitLab repo using your Personal Access Token like this:

git clone https://oauth2:[email protected]/yourself/yourproject.git

As for how to update your existing clones to use the GitLab Personal Access Token, you should edit your .git/config file in each local git directory, which will have an entry something like this:

[remote "origin"]
    url = https://[email protected]/yourself/yourproject.git

Change the url:

[remote "origin"]
    url = https://oauth2:[email protected]/yourself/yourproject.git

Now you can continue using this existing git clone as you did before you enabled 2FA.


I used the generated Personal Access Token as the password when prompted to enter credentials.

This allowed me to just use the standard Git Clone syntax without entering anything additional.

When you generate, copy the token. This is the password that will be stored in Credential Manager when you clone. Use that as your password instead of your git password.


Visit the below link and enter your Name and Expiry Date.

Then click on the different checkboxes like read_user, read_repository, write_repository, etc for access scopes and create a new Personal Access Token and store it in a secured location

https://gitlab.com/profile/personal_access_tokens

Now when you do a git pull, git clone, git push, etc you can enter your username/email as the Username and enter the newly created Personal Access Token as Password


See the link below enter link description here

You just need to create a new token for your profile! To do this,

  1. click on your photo and then enter the Edit Profile section
  2. click on Access Tokens
  3. Create a new token with the permissions you need
  4. Now copy the created token according to the photo below enter image description here
  5. git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY
  6. Enter your username, but use the created token instead of the password!