Cloning from GitLab

Cloning from GitLab is how you create a local copy of a project repo hosted on GitLab. You have two options:

  1. read-only — just clone something public without any authorization,
  2. read-write — clone and make changes you can commit and push.

Although both methods can use either https or git URLs I use http (no s) for read-only and git for read-write.

But First …

You need to have a project repo created or forked from another before you can clone it.

Step by Step

Pick one of the following:

  1. Cloning a Project Repo to Work On
  2. Cloning Public Read-Only Project Repos

Cloning a Project Repo to Work On

Cloning a project repo that you are going to work on requires you to have write access to the it, which means you must have a public-private key pair setup if using ssh, which you always should.

Navigate into your repos directory.

cd repos

Now all you need to do is change the following to match your account and the path of your project repo.

💎 You can save time by cutting pasting the SSH URL in GitLab. Click on the blue Clone button to get it.

If you are cloning something in your personal account (not a group / organization), then do something like this (using your own info).

git clone

If you are cloning something from your group or sub group it might look like one of the following:

git clone
git clone

❤️ I absolutely love the ability only GitLab gives you to organize your many project repos under subgroups. GitLab really is objectively superior to GitHub in many ways..

You might see something like this if it is your first time cloning a brand new project repo and you haven’t put anything in it.

Cloning into 'www'...
warning: You appear to have cloned an empty repository.

If you see something like this you have cloned an existing project repo with something in it already.

Cloning into 'www'...
remote: Enumerating objects: 12, done. 
remote: Counting objects: 100% (12/12), done. 
remote: Compressing objects: 100% (8/8), done. 
remote: Total 12 (delta 1), reused 0 (delta 0)
Receiving objects: 100% (12/12), done.
Resolving deltas: 100% (1/1), done.

You can change into this directory now and work.

For example, if the project is www you would do this:

cd www

If you are using VSCode then you can reset it to this directory.

code -r .

The code means VSCode.

The -r does the resetting. Don’t forget it. Actually it means reuse but who cares. Just always use it anyway.

The . means “this directory right here that I’m in currently.”

Cloning Public Read-Only Project Repos

To clone a public repo all we need is the http (no s) version of the URL. You can get this from GitLab (or GitHub) but normally you can just work it out from the following pattern:

git clone

You may note that it redirects to https, which is fine. [GitHub has trouble with https for this sort of stuff.]