In the last lesson, we looked at
how we can push our Local Repository
to a Remote Repository on GitHub.
Now, in this lesson, I want to talk about
cloning a Remote Repository on GitHub to pull it
onto your Local Repository on your machine.
So this is called cloning, and the command is git clone.
And this is a way for you to pull down all of the versions
and all of the commits of a particular remote repository,
and to store the files in your own working directory.
So once you've cloned a repo,
you've essentially made a copy of it
on your own local working environment,
and it allows you to stand on the shoulder of giants
and continue where they left off.
So you won't need to clone it again
during regular development,
you'll continue on your own branch of that project.
So why would you need to clone someone else's project?
Well, it's basically so that you can have your own copy
of a program that they wrote.
Maybe you want to customize it to your own needs.
Maybe the program needs to do something it currently
doesn't do, and you want to extend its functionality.
Or maybe you just found a bug and you want to fix it.
So essentially, it allows you to leverage
somebody else's open source code,
so they're putting their source code out onto the internet
and you can simply make a copy of it,
and continue where they left off.
For example, a lot of people use
self-hosted applications for their business.
These are free versions of projects
and services you might have to normally pay for,
such as productivity and project management tools
that are alternative to Jira
or Trello or email servers like MailChimp.
Instead of having to pay Mailchimp a ton of money,
you can host your own email servers,
or time tracking software for freelancers.
And there's a ton, a ton, literal ton of different options
and you can take a look through that in this GitHub README.
Let's see how it works in practice.
Let's clone some actual repo's from GitHub
and run them locally to see how the entire process works.
The command is pretty simple.
It's simply git space clone space the url (git clone url).
But the url will typically be from GitHub
and it will look something like this.
So what are we going to clone?
Well, did you know that you can run
the original Quake video game in your web browser?
It's entirely built in JavaScript,
so there'll be parts of it
that you'll be able to read through,
and you'll be able to understand.
But there'll be a lot of work
that's done to create this game.
So thankfully, we don't have to build it from scratch.
All we have to do is just to git clone.
I go ahead, I grab the url to clone the repository,
and in my terminal I can write git clone
and paste in that url.
Now, once it receives all of the objects,
and it gets loaded onto my own computer,
then I can go ahead and cd into the repository, quakejs.
And once I'm inside that repository,
I can install all of the NPM packages
by running "npm install".
And then the next step as they describe in the documentation
is I need to set the content .quake.js.com
as the content server.
So I'm just going to simply copy this entire line
of commands and paste it into my terminal.
Now, once I'm done, I can simply run the server using Node
by again pasting this line of commands.
And once it starts,
you can see that, "web server is now listening on port :::8080".
And so now I can go to that port
and check out the Quakejs game.
So making sure that your url is the same
as the one that they have set in their documentation,
go ahead and agree,
and you'll see once everything's loaded up,
the original Quake game running on your browser.
But more importantly, you are running it
from the code that you cloned from GitHub.
So feel free to have a play around with the game.
It's pretty cool and it's very retro.
And there you have it.
Now another example is Wordle.
Wordle is basically a word game where you have to guess
a five letter word using just six tries,
and it went completely viral a few years ago,
and eventually got bought by the New York Times.
And the official Wordle is now accessed
at the New York Times
alongside all of their different crosswords and puzzles.
But somebody has created all the code for Wordle,
and we can clone it and run it on our own system.
So again, grabbing hold of the URL at the GitHub repository,
you can see it's entirely created
in Python and uses Tkinter.
So all the things that we know about,
we can head back to our terminal,
use git clone to clone from that url,
and then we open the folder
and set up our virtual Python environment.
And the reason why they created it is
because the original game only allows
you to play one word per day,
but what if you get entirely addicted to Wordle
and you want to play more than one word per day?
Well, you're in luck because you know how to clone
the program and run it on your own system.
Now all we have to do is just to install
all of the required modules,
and once that's done, we can click on play
and the game will start in a separate window.
Go ahead, have a guess, see what you have.
And my personal starting word, top secret is usually, NOTES
or another word with R and T and S.
But have fun playing with that.
And you can dig through the code,
you can change it from Wordle game
to anything else you want to call it.
Or you can change the colors.
You can modify the code base,
because you now own it on your own computer,
and you can run it,
and you can modify it.
And you can see just how cool it is
to be able to simply clone somebody else's entire code base
that they've made open source
for you to continue developing on it.
So look through the code, open it up,
and take a look inside the word files
to see all of the available words.
There's no cheating here.
And you'll be able to see the actual code
that makes this game run.
So you can see it's just simple Python
which you know all about.
And some of these things you might not understand.
But through studying somebody else's code and modifying it,
it usually makes you a much better developer.
Go ahead, try to improve your own version,
make it a 2.0 Wordle, whatever that means to you.
And this is a big part of your developer journey.
One of the best ways to improve your programming skills
is to read other people's code to understand
what their code is doing, and most importantly,
try to modify it just a little bit
at the beginning and maybe a lot more in the future.
But it gives you a way to level
up your skillset by building on top of somebody else's work.
And open-source code is a great way to get started.
You can clone somebody's repository,
take a look at some of the more interesting ones
that we've listed here such as Wordle or Jarvis.
See roughly how things work and see if there are
just small things that you might want to change about it.
And this will lead you onto a very important step
on your developer journey,
which is contributing to open source code.
Now, there's a lot of projects,
there's even a list of projects
on GitHub where they have curated some projects
which are particularly welcoming to first time contributors.
So teams which are open
for first timers or beginners to contribute.
And you can take a look at that by going to
awesome-for-beginners, this particular repository,
and take a look through the README.
Take a look at maybe the pandas module
or take a look at Jarvis or Matplotlib.
You can contribute to all of these,
but in order to know how to make a contribution,
you need to learn about pull requests, branches, and merging
which is exactly what we'll cover in the upcoming lessons.
So for all of that and more, I'll see you there.