Git 03: Git Clone - Work Locally On Your Computer

Megan A. Jones
Table of Contents

This tutorial covers how to clone a repo to your computer so that you can work locally on files within the repo.

Learning Objectives

At the end of this activity, you will be able to:

  • Be able to use the git clone command to create a local version of a GitHub repository on your computer.

Additional Resources

Clone - Copy Repo To Your Computer

In the previous tutorial, we used the interface to fork the central NEON repo. By forking the NEON repo, we created a copy of it in our account.

When you fork a reposiotry on the website, you are creating a duplicate copy of it in your account. This is useful as a backup of the material. It also allows you to edit the material without modifying the original repository. Source: National Ecological Observatory Network (NEON)

Now we will learn how to create a local version of our forked repo on our laptop, so that we can efficiently add to and edit repo content.

When you clone a repository to your local computer, you are creating a copy of that same repo locally on your computer. This allows you to edit files on your computer. And, of course, it is also yet another backup of the material! Source: National Ecological Observatory Network (NEON)

Copy Repo URL

Start from the interface:

  1. Navigate to the repo that you want to clone (copy) to your computer -- this should be YOUR-USER-NAME/DI-NEON-participants.
  2. Click on the Clone or Download dropdown button and copy the URL of the repo.
The clone or download drop down allows you to copy the URL that you will need to clone a repository. Download allows you to download a .zip file containing all of the files in the repo. Source: National Ecological Observatory Network (NEON).

Then on your local computer:

  1. Your computer should already be setup with Git and a bash shell interface. If not, please refer to the Institute setup materials before continuing.
  2. Open bash on your computer and navigate to the local GitHub directory that you created using the Set-up Materials.

To do this, at the command prompt, type:

$ cd ~/Documents/GitHub

Note: If you have stored your GitHub directory in a location that is different - i.e. it is not /Documents/GitHub, be sure to adjust the above code to represent the actual path to the GitHub directory on your computer.

Now use git clone to clone, or create a copy of, the entire repo in the GitHub directory on your computer.

# clone the forked repo to our computer
$ git clone

Data Tip: Are you a Windows user and are having a hard time copying the URL into shell? You can copy and paste in the shell environment after you have the feature turned on. Right click on your bash shell window (at the top) and select "properties". Make sure "quick edit" is checked. You should now be able to copy and paste within the bash environment.

The output shows you what is being cloned to your computer.

Cloning into 'DI-NEON-participants.git'...
remote: Counting objects: 3808, done.
remote: Total 3808 (delta 0), reused 0 (delta 0), pack-reused 3808
Receiving objects: 100% (3808/3808), 2.92 MiB | 2.17 MiB/s, done.
Resolving deltas: 100% (2185/2185), done.
Checking connectivity... done.

Note: The output numbers that you see on your computer, representing the total file size, etc, may differ from the example provided above.

View the New Repo

Next, let's make sure the repository is created on your computer in the location where you think it is.

At the command line, type ls to list the contents of the current directory.

# view directory contents
$ ls

Next, navigate to your copy of the data institute repo using cd or change directory:

# navigate to the NEON participants repository
$ cd DI-NEON-participants

# view repository contents
$ ls          _includes       code   _layouts        images       _posts
_config.yml     _site           institute-materials
_data           assets          org

Alternatively, we can view the local repo DI-NEON-participants in a finder (Mac) or Windows Explorer (Windows) window. Simply open your Documents in a window and navigate to the new local repo.

Using either method, we can see that the file structure of our cloned repo exactly mirrors the file structure of our forked GitHub repo.

Thought Question: Is the cloned version of this repo that you just created on your laptop, a direct copy of the NEON central repo -OR- of your forked version of the NEON central repo?

Summary Workflow -- Create a Local Repo

In the interface:

  • Copy URL of the repo you want to work on locally

In shell:

  • git clone URLhere

Note: that you can copy the URL of your repository directly from GitHub.

Got questions? No problem. Leave your question in the comment box below. It's likely some of your colleagues have the same question, too! And also likely someone else knows the answer.

Dialog content.