- Identify a remote repository
- Copy a repository to your local machine with
git clone - List remotes with
git remote - Duplicate other organizations' repositories into your own via GitHub with
git fork
Now that we've created local Git repositories, we can create logged histories of our projects. What's great about Git and open source is that lots of people are doing the exact same thing all around the world all the time.
Our next step is to learn how to get others' repositories. In a later lesson we'll cover how to push our locally-created repositories onto the internet so that others can see our projects. But one step at a time.
To work with or collaborate on any Git project, you need to be able to manage your remote repositories. Remote repositories are versions of a repository that are hosted online—typically, on GitHub.
We use git clone to copy someone else's remote copy of their local repository
to our machine.
- Navigate to the https://github.com/facebook/react repository
- Click the "Clone or Download" green button on the right.
- Make sure you select
Use SSHas your URL type.
- Click the "Copy to clipboard" button (highlighted below). This will copy the URL for us to use when we clone.
- In the terminal (accessed through the 'Sandbox' or Learn IDE), we run the
git clonecommand. It takes the URL we just copied as an argument, like so:
git clone your-copied-github-urlThis will create a local copy of the GitHub repository on our own machine.
If you use the ls command, you'll see Git created a directory called
react. Use cd to enter that directory.
cd reactType git remote to see each remote available.
If you've cloned your repository, you should at least see origin. The remote
called origin is the default name Git gives to the remote you cloned from:
$ git remote
originForking a GitHub repository is just a way to create a personal, online duplicate of it. When you fork a lab, GitHub creates a duplicate from the source organization's online version of the repository to your local duplicate of the repo.
It's like saying "Hey, can I have the Louvre's version of The Mona Lisa?" The
Louve would say no. If you were to create an exact online duplicate by forking
it from louvre/mona_lisa to your-name/mona_lisa the Louvre would be cut out
of the, pardon the pun, picture. You could then copy your organization's
version to your local machine with git clone.
Forking is a very common workflow for working with teams or working with or contributing to open sourced content in the GitHub community. You can fork any repository by clicking the "Fork" button at the top right of any GitHub repository.
Let's try a fork and clone workflow.
Click the GitHub icon at the top of this page:
This will bring you to the "learn-co-students" version of this lesson. Click the
'Fork' button in the upper right corner of the page. You will be prompted to
choose where the repository should be forked to, so go ahead and choose your
account. GitHub will take a few moments to create the fork, then navigate to
your copy of the repository. If all has gone well, you will see your username at
the top of the page, followed by a / and the name of the repository, along
with a link just below to the original repository. (More on forking in the GitHub docs.)
The important take away is to not misuse "fork" and "clone" when speaking
with other Git users. To get a local copy: clone; to make an online copy of
a repository to your personal organization so that you have the ability to
update its master branch, fork.
Often, the original authors will include license information regarding how you can use their repository, so make sure to check before you publish, sell or distribute any material you've forked, cloned and modified.
GitHub gives developers many ways to collaborate. Using git fork and git clone together allows you to make local copies of others' code. As you saw with
cloning React, this is something you can do on any public GitHub repository.
So if you've found a GitHub repository that you'd love to modify for your own
use, you can use this process to make your own copy and modify away.



