Skip to main content

Git for Authors

Section B.4 Copying a GitHub Repository (Forks, Clones)

For collaborators to work independently on a project, they need their own independent copy of a repository. On GitHub you can visit somebody else’s repository and fork that repository. This will make an entire independent copy of that person’s repository in your account (where you have permission to modify your copy), and GitHub will remember where your copy came from. In this case the copy is known as a fork. Yes, the word fork has just been used as a verb, “Cameron forked Drew’s repo”, and is also used as a noun, “Cameron’s fork of Drew’s repo.” Making a fork of someone’s project is a compliment, since it suggests interest, and the possibility of someday contributing back to the project, in the style of Chapter 4.
You can also, and often may prefer, to copy a repository to your local computer. You might like to write while on airplanes, on your desktop at work, or on your laptop at home in bed. Then you can even collaborate with yourself and keep all those repositories syncronized. So you could have copies of your project all over the place.
It is easy to copy a git repository generally, and dead-simple to copy a GitHub-hosted repository. To copy a GitHub repository, you need to know the URL. It is a bit hidden. On the main page for a project (yours, or somebody else’s), locate and click on the green Code button, and the URL should be visible. You are looking for something like
https://github.com/alice-jones/banking-paper.git
which would fit our first GitHub example. Copy the URL to your clipboard.
Now open a terminal on your local machine where you can use the command-line. Navigate to a directory, where a new repository-specific directory makes sense for your work. In our first example, Alice might navigate to her existing ~/papers/ directory, where she expects to soon have a ~/papers/banking-paper directory. OK, all set. Making a copy is known as a clone. (And a fork is just a special type of clone.)
alice@work:~/papers$ git clone https://github.com/alice-jones/banking-paper.git
Cloning into 'banking-paper'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
Checking connectivity... done.
The above may take a long time for a large repository (many large files, or a long history of many, many changes). The output above is for an essentially empty repository. Now verify the expected directory exists and has the expected files in it.