Now we have our own fork on GitHub, but we also need a local clone to work on it using Git on our machine.
A clone is a complete copy of a repository, including all its history and versions of files.
Navigate back to the original repository and click the green “Code” button to get the URL for cloning:
Open Git Bash and clone the repository:
[user@localhost] $ |
git clone https://github.com/code7school-test/code7school-test.github.io.git |
Check your file system, and you’ll see a new directory named after the cloned project.
[user@localhost] $ |
ls |
Note: To clone the repository into a specific folder, add the folder name after the repository URL, like this: git clone https://github.com/code7school-test/code7school-test.github.io.git myfolder. |
Go to the new directory and check the status:
[user@localhost] $ |
cd code7school-test.github.io nothing to commit, working tree clean |
And check the log to confirm that you have the complete repository data:
[user@localhost] $ |
git log Merge branch ‘master’ of https://github.com/code7school-test/hello-world commit e7de78fdefdda51f6f961829fcbdf197e9b926b6 Updated index.html. Resized image ….. |
Now, we have a complete copy of the original repository.
Essentially, we have a full copy of a repository that we don’t have permission to modify directly.
Next, let’s check how the remotes are configured for this Git repository:
[user@localhost] $ |
git remote -v origin https://github.com/code7school-test/code7school-test.github.io.git (fetch)origin https://github.com/code7school-test/code7school-test.github.io.git (push) |
We see that origin is set up to the original “code7school-test” repository, we also want to add our own fork.
First, we rename the original origin remote:
[user@localhost] $ |
git remote rename origin upstream |
Then retrieve the URL of our own fork:
And set that as the origin:
[user@localhost] $ |
git remote add origin https://github.com/kaijim/w3schools-test.github.io.git |
Note: According to Git naming conventions, it’s recommended to name your own repository origin and the original repository you forked from upstream. |
Now we have two remotes:
Next, we’ll make some changes to the code. In the following chapter, we’ll cover how to propose those changes to the original repository.