init: git clone
In this video we’ll learn how to use
git clone is the same as
However, instead of initializing an empty repository,
git clone copies a repository from a URL.
In doing so, it copies all the files tracked by Git as well as the commit history and references. Or more technically, the .git directory.
Let’s demonstrate this by cloning the Getting Git repository we forked on GitHub.
First, I’ll visit GitHub to get the clone URL.
There are often two options: HTTPS and SSH. I often prefer using SSH as I already have an SSH key shared with GitHub.
I’ll cover creating SSH keys and using HTTPS with a credentials helper in one of the Everyday Git videos.
For now, feel free use HTTPS if you haven’t setup your SSH key.
So, I’ll copy the SSH clone URL.
I'll go back to the command line and navigate to my workspace
Then I'll run
git clone and paste the clone URL.
git clone a directory of the project name
If I change into the cloned directory and run
ls -la, we can see all the files from the repository were copied as well as the .git directory.
In addition, if I run
git log --oneline we can see the full commit history.
Finally, if I run
git status notice a new line is added to the output.
This line outputs the status of the local repository compared to the repository on GitHub.
Since you'll usually only copy a repository once,
git clone is not a command you'll use very often. Nonetheless, it has a few additional uses we'll learn in the Master video.