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.


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


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.