Chirag S

[Solved] Can't Clone GitLab Repository Via Http

Published on February 13th , 2022
  • GitLab
[Solved] Can't Clone GitLab Repository Via Http

Oh, I just love repositories. Don’t you? It’s just amazingly helpful. Ok, that was lame but the feelings are real.

I’ve been using GitLab for a while now and I can honestly say that it’s really very useful. The tools and transparency it brings to the table are unlike any other. Especially the ability to host a static website with a private repository. Not literally! I’ll explain this in a bit.

Why not Github or Azure Repo or any other?

Quite honestly, I was looking for a free option to host my static website. Now, why free? well, I’m kind of a little short on cash so there! there is the reason!

GitLab solves this problem. I can host a repository with the source code on GitLab and keep it secured and still host the website publically. How I did it is beyond the scope of this post but just let know down in the comment section and I’ll create contents specifically to help with that.

The Problem

Recently, I enabled 2-step verification in my GitLab account and ever since then, I couldn’t clone my repositories. The reason is that since I enabled 2-step verification, that extra layer of security is not supported when I try to clone the repository from the command line.

The Solution

So turns out that I needed to create a personal token from my profile and then clone the repository with the following command.

https://<my-user-id>:<my-password>@gitlab.com/<my-account>/<my-project-name>.git

https://gitlab.com/<my-account>/<my-project-name>.git?personal_access_token=<my token>

If your token is abcdefg, your username is testuser, password testpassword, your account testaccount, and your project is testproject, the command would be,

https://testuser:[email protected]/testaccount/testproject.git

https://gitlab.com/testaccount/testproject.git?personal_access_token=abcdefg

Here is how you can find those parameters,

Access Token: you can click on your profile picture in the top right corner and go to Preferences => Access Tokens and generate a new one with Read and Write permission to repositories.

Username: You can follow the same previous step but this time goes to Preferences -> Account and there you’ll find it.

Account: In most cases, this is your username but if it’s not working, go to your repository and click on the Clone button and you’ll find it in the copied URL.

Project Name: You’ll find this in the same link from the previous step.

Problem solved!