In this lesson, you will learn how to create a copy of other users’ files on
GitHub (i.e. forking) and to use the
Terminal to download the copy to your computer (i.e. cloning).
After completing this lesson, you will be able to:
- Explain how
Gituse repositories to store and manage files
- Create a copy of (i.e.
fork) other users’ files on
- Use the
Git clonecommand to download your copy of files to your computer
What You Need
Be sure that you have completed the instructions on Setting up Git, Bash, and Anaconda on your computer to install the tools for your operating system (Windows, Mac, Linux).
Be sure that you have completed the previous lesson on Intro to Shell.
You will also need a web browser and your
Github.com login (username and password).
About Git & GitHub
In the lesson on Open Reproducible Science, you learned that
Git is tool that is used to track changes in files (a process called version control) through a suite of commands that you can execute in the
Terminal. You also learned that
GitHub is the cloud-based version of
Git, which can be used to store files in the cloud to access them from any computer and to share them with others.
GitHub use repositories (i.e. directories of files stored on
Github.com) to manage and store files.
Data Tip: A
GitHub repository is a directory of files and folders that is hosted on
GitHub allows you to store a set of files as Github repositories in the cloud (on the
GitHub servers) and to work with these repositories locally on your computer using
Git commands in the
Having a copy of a set of files as repositories in the cloud is ideal because:
- There is a backup: If something happens to your computer, the files are still available online
- You can share the files with other people easily
- You can even create a Digital Object Identifier (DOI) using third party tools like Zenodo to cite your files or ask others to cite your files. You can also add these DOIs to your resume or C.V. to promote your work.
Forking and Cloning Repositories
In this lesson, you will learn how to make a copy of an existing repository created by another user or organization (a task referred to as
forking repositories) and to download your copy of the repository to your computer (a task referred to as
The ability to
fork a repository is a great benefit of using
GitHub repositories because the forked repository is linked to the original. This means that you can download new updates from original to your forked repository as well as suggest changes to the original repository, which can be reviewed by the owner of that repository.
Cloning a repository to your computer is a great way to work on your files locally, while still having a copy of your files on the cloud on
Throughout the course, you will learn more about the functionality provided by
Git. In this lesson, you will first
fork an existing repository on
Github.com to make a copy for yourself, and then run the
git clone command from the
Terminal to download your copy of the repository to your computer.
Create a Copy of Other Users’ Files on Github.com (Forking)
The URL link to a
GitHub repository always follows the same format:
fork an existing
Github repository from the main
Github.com page of the repository that you want to copy (example:
On the main
Github.com page of the repository, you will see a button on the top right that says
Fork. The number next to
Fork tells the number of times that the repository has been copied or forked.
Click on the
Fork button and select your
Github.com account as the home of the forked repository.
Copy Files From Github.com to Your Local Computer (
Now that you have made a copy (or forked) the desired repository, you will use the
git clone command to download the forked repository (i.e. your copy of a
GitHub repository) from
Github.com onto your computer.
Bash to Change to Your Desired Working Directory
The first step to using any
Git command is to change the current working directory to your desired directory.
In the case of
git clone, the current working directory needs to be where you want to download your local copy of a
GitHub repository. You will use the
earth-analytics-bootcamp directory that you created under your home directory in the previous lesson.
$ cd ~ $ cd earth-analytics-bootcamp $ pwd /users/jpalomino/earth-analytics-bootcamp
Copy a Github.com Repository URL From Github.com
Because you forked the
ea-bootcamp-day-1 repository, your
Github.com account now contains a copy of it, which you can access on
On the main
Github.com page of your forked repository, click on the green button for
Clone or download, and copy the URL provided in the box, which will look like:
Note: you do not have to use the
Clone or download button to copy the URL. You can also copy it directly from your web browser or you might simply already know the URL. However, in many cases, you will have come across a
Github.com repository on your own and will need to follow these instructions to copy the URL for future use.
Run the Git Clone Command in the Terminal
To download your forked copy of the
ea-bootcamp-day1 repository to your computer, be sure that you have changed to the correct working directory (see Use
Bash to Change to Your Desired Working Directory).
Then, run the command
git clone followed by the URL that you copied in above as follows:
git clone https://github.com/your-username/ea-bootcamp-day-1
You have now made a local copy of the forked
Github.com repository under your
earth-analytics-bootcamp directory. Double check that the directory exists using the
ls command in terminal.
$ ls ea-bootcamp-day-1
GitHub skills to
clone the repository for Homework 1:
On Day 1 of the course, you will receive an email invitation to Homework 1 via
Accept the invitation, which will create a new private repository that includes your
Github.comusername in the name of the repository:
Forkthis repository to your
GitHub account. Your forked repository will be available on
Clone your forked repository
earth-analytics-bootcampdirectory on your computer (hint:
ea-bootcamp-hw-1-yourusernamehas been successfully cloned to your computer (hint:
What other directories are present in the