Git Clone from GitLab
Clone a Fork from GitLab
Now we have our own fork
, but only on
GitLab. We also want a
clone
on our local Git to keep working on it.
A clone
is a full copy of a repository, including all logging and versions of files.
Move back to the original repository, and click the green "Code" button to get the
URL
to clone
:
Open your Git bash and clone
the repository:
Example
git clone https://gitlab.com/w3schools-test/w3schools-test.gitlab.io.git
Cloning into 'w3schools-test.gitlab.io'...
remote: Enumerating objects: 41, done.
remote: Counting objects: 100% (41/41), done.
remote: Compressing objects: 100% (41/41), done.
remote: Total 41 (delta 22), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (41/41), 95.11 KiB | 2.21 MiB/s, done.
Resolving deltas: 100% (22/22), done.
Take a look in your file system, and you will see a new directory named after the cloned project:
Example
ls
w3schools-test.gitlab.io/
Note: To specify a specific folder to clone to, add the name of the folder after the repository
URL
, like this:
git clone https://gitlab.com/w3schools-test/w3schools-test.gitlab.io.git myfolder
Navigate to the new directory, and check the status
:
Example
cd w3schools-test.gitlab.io
git status
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
And check the log
to confirm that we have the full repository data:
Example
git log
commit da5469e68bc7ad9293d72ec218a2732337c505ad (HEAD -> master, origin/master, origin/HEAD)
Author: w3schools test
Date: Wed Apr 28 08:42:37 2021 +0000
Added configuration for GitHub Pages
commit 7550c4e54171d6aa060d42f30513d6857e7ae0e4
Merge: e2ccf59 3361404
Author: w3schools test
Date: Wed Apr 28 08:16:52 2021 +0000
Merge branch 'update-readme' into 'master'
Update readme with branches info
See merge request w3schools-test/hello-world!1
.....
Now we have a full copy of the original repository.
Configuring Remotes
Basically, we have a full copy of a repository, whose
origin
we are not allowed to make changes to.
Let's see how the remotes
of this Git is set up:
Example
git remote -v
origin https://gitlab.com/w3schools-test/w3schools-test.gitlab.io.git (fetch)
origin https://gitlab.com/w3schools-test/w3schools-test.gitlab.io.git (push)
We see that origin
is set up to the original "w3schools-test
" repository, we also want to add our own fork
.
First, we rename
the original origin
remote
:
Example
git remote rename origin upstream
git remote -v
upstream https://gitlab.com/w3schools-test/w3schools-test.gitlab.io.git (fetch)
upstream https://gitlab.com/w3schools-test/w3schools-test.gitlab.io.git (push)
Then fetch the URL
of our own fork
:
And add that as origin
:
Example
git remote add origin https://user@gitlab.org/user/w3schools-test.gitlab.io.git
git remote -v
origin https://gitlab.com/kaijim/w3schools-test.gitlab.io.git (fetch)
origin https://gitlab.com/kaijim/w3schools-test.gitlab.io.git (push)
upstream https://gitlab.com/w3schools-test/w3schools-test.gitlab.io.git (fetch)
upstream https://gitlab.com/w3schools-test/w3schools-test.gitlab.io.git (push)
Note: According to Git naming conventions, it is recommended to name your own repository
origin
, and the one you forked for
upstream
Now we have 2 remotes:
origin
- our ownfork
, where we have read and write accessupstream
- the original, where we have read-only access
Now we are going to make some changes to the code. In the next chapter, we will cover how we suggest those changes to the original repository.