So the first thing we're going to cover is cloning.
Cloning is a really important part of working with remote repositories.
In fact, it's such an important thing that we do and get if we go to the documentation under reference,
all the commands are grouped together like the basic snapshot and commands adding and get status, get
commits, branching and merging.
They're grouped together.
But then up top there are two commands side by side, getting and creating projects init and clone.
So we've seen how to use git init to create a new project or a new repo from scratch.
We've done that for every repository but get clone does something different.
Git clone actually goes and gets a repository that is not on your machine and it brings it to your machine.
It basically downloads the contents of a repository based upon some URL that we provide.
Typically, that URL will be from a service like GitHub.
And in this course and 99% of the open source projects out there, it will be a GitHub repository that
you're cloning, but it could be something else.
Bitbucket It could be a self-hosted repository.
Git does not care.
The command get clone is part of Git.
It's not part of GitHub.
So here it is.
Get Clone and then a URL.
And that URL is where git will go and retrieve all the relevant information for repository from it.
Will copy the files to your machine.
It initializes a new repository on your machine so that gives you access to the full git history of
whatever project you're cloning.
And I'm going to demo this in just a moment.
So as an example, there's some repository on GitHub.
Let's say it's I don't know, it's it's React or it's a Flappy Bird clone.
It's some game on GitHub.
I want the source code and the get history.
So if I run Git clone with the corresponding URL, whatever that GitHub URL is for that hosted repo,
git is going to go fetch all of that and bring it down to my machine.
I'll have the full history, all the commits, all the files, so I'll go ahead and demonstrate this.
Here's a GitHub repository that I don't have.
It's for the game 2048, which some of you probably know this game very addictive.
It's I don't know how many years old now, but anyway, it's just a JavaScript, HTML, CSS that it's
a game.
You can open it up and play it in your browser.
So if I want the code for that and I want the full git history, of course I can see it on GitHub.
That's what GitHub is doing for me here.
As a user, I can view this URL, I can look at different commits, 180 commits, I can see who contributed.
I can read about it.
I can take a look at the index HTML file in the browser, but I'm going to clone this URL.
One option is just to copy this URL right here.
Another option on GitHub is to click right here and it's going to show me the clone URL, which is the
same thing as we see up there.
I can click this button, I can command see however you want to get that URL, I'm going to get that
URL.
And by the way, this repository link is in the resources with this video.
If you want to try this, definitely recommend you do.
Now I'm going to go over to my terminal.
The first thing you always want to do when you're cloning is make sure that you're not in a repository
just like when you run git init.
So I just like to do get status.
We're not in a repository and then wherever you run git clone that is the place that folder where Git
is going to create a new folder for you.
So I'm in a folder called what is this?
Just.
Well, actually, I meant to be in this folder cloning.
So now I'm in a folder cloning.
There's nothing in here.
It's going to make me a new folder when I run this command git clone and then I paste the URL that's
coming from GitHub.
I don't have anything from this URL.
I don't have this repository on this machine.
I'm not in a git repo.
But when that finishes and you will need Internet for this, when that finishes, we see a new folder
that was not there before I typed ls there was nothing.
If I go into that folder and I type ls OC I've got a whole bunch of stuff, right?
I've got index, HTML, JavaScript, folder, style folder, some other stuff going on.
And it looks like this is a git repo, right?
If I type get status.
Yes, it is.
If I type git log, I can see the full history of commits.
See all that stuff.
That's all.
Or it came from GitHub.
I can see all the commits and who made them when they were made.
There's all the code here.
I can open it up and take a look.
I can even run this.
And there this is actually running.
This is not the hosted version.
This is running from my machine.
You can see here and there we are.
I could play around with it myself.
I could change the styles.
I've opened up the CSS, main CSS, and I could do something like a sort of background.
What are we doing with the background color somewhere?
Oh, there we are.
Let's make that some form of green or olive.
Sure.
All live just like that.
So pretend I've tweaked a whole bunch of things.
I can see those changes, right?
This is all just for me to experiment and play around with locally.
Although in the next couple of sections I'll also show how we could make changes and then try and contribute.
Try and share these changes with the owner of the repository.
Try and suggest maybe not this, but maybe there's a bug that someone's identified and I volunteered
to fix it.
I would need to clone the repository, whether I'm just messing around and breaking things and playing
and changing colours, whether I'm trying to understand how something works or whether I want to make
contributions I need to clone.
So that command git clone.
It's pretty simple, right?
Just get clone and then a URL.
Make sure you're not in a git repository when you run it because it creates well, it creates a folder.
But in that folder there is a git repository that's been initialized and it has the full history of
the project.
I'm just showing it to you and get cracking very quickly.
This is the cloned repository and we can see a lot of commits going on as I scroll, a lot of different
branches over time, a lot of different contributors, and I could take a look at any of them.
I could go all the way back to the beginning.
Oh, boy, look, initial commit, basic styling, the very basic stuff like add wind win conditions
so you can win the game all the way up to things up top where other developers have contributed.
I'll just show one more example.
This is another GitHub repository.
This one is just a list.
It's a list of companies that hire without whiteboarding interviews, without the bad computer science
trivia questions that don't actually test your abilities as a developer.
It's open source.
People contribute different companies that are on here.
If I want this repository for whatever reason on my machine, never mind the fact that you just it's
probably easier to view it here.
But if I wanted to contribute an ad, I could copy this URL.
Right?
Or I can click here and copy that there the same URL go to my terminal, which is somewhere there we
are.
Make sure I'm not in a get repo and I am right now so I'm going to back out and now I'm not type get
status I'm not get clone paste that URL.
It takes a moment.
This one is a bit larger.
And then I have a new folder.
Hiring without whiteboards get status inside.
Yes, it is a repository I type LRS.
We can see all the files here and I type git log and I can see all of the contributions, all the individual
commits.
There's quite a bit here.
Let's do a one line.
And then I can scroll through all of them.
I could open this and get cracking and show you the same thing.
I have the full history for that entire repository on my machine.
I didn't create the repository.
Right.
I just cloned it using git clone.
Great command.
Excellent.
Excellent, great command.
Remember, it's a git command.
It is not tied to GitHub.