Cloning from GitLab
Cloning from GitLab is how you create a local copy of a project repo hosted on GitLab. You have two options:
- read-only — just clone something public without any authorization,
- read-write — clone and make changes you can commit and push.
Although both methods can use either
git URLs I use
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.
- Making Sure You Have an Internet Connection
- Setting Up GitLab on Your Workstation
- Forking a GitLab Project Repo
- Creating a GitLab Project Repo
Step by Step
Pick one of the following:
- Cloning a Project Repo to Work On
- 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 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 firstname.lastname@example.org:robmuh/myproj.git
If you are cloning something from your group or sub group it might look like one of the following:
git clone email@example.com:skilstak/grouproj.git git clone firstname.lastname@example.org:skilstak/config/vim.git
❤️ 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 pwd
If you are using VSCode then you can reset it to this directory.
code -r .
code means VSCode.
-r does the resetting. Don’t forget it. Actually it means reuse but who cares. Just always use it anyway.
. 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 http://gitlab.com/skilstak/config/vim.git
You may note that it redirects to
https, which is fine. [GitHub has trouble with
https for this sort of stuff.]