Bootcamps

Explore our extensive collection of courses designed to help you master various subjects and skills. Whether you're a beginner or an advanced learner, there's something here for everyone.

Academy

Learn live

Join us for our free workshops, webinars, and other events to learn more about our programs and get started on your journey to becoming a developer.

Upcoming live events

Learning library

For all the self-taught geeks out there, here is our content library with most of the learning materials we have produced throughout the years.

It makes sense to start learning by reading and watching videos about fundamentals and how things work.

Full-Stack Software Developer - 16w

Data Science and Machine Learning - 16 wks

Search from all Lessons


LoginGet Started

Weekly Coding Challenge

Every week, we pick a real-life project to build your portfolio and get ready for a job. All projects are built with ChatGPT as co-pilot!

Start the Challenge

Podcast: Code Sets You Free

A tech-culture podcast where you learn to fight the enemies that blocks your way to become a successful professional in tech.

Listen the podcast
← Back to How to's
Edit on Github

How to clone a github repository

Written by:

GitHub Clone Repository

You can clone a git repository as simply as follows:

1$ git clone <git-repository-url>

<git-repository-url> should be replaced by the link of the repository that you want to clone, like this:

1$ git clone https://github.com/4GeeksAcademy/html-hello

Cloning a repository creates a local copy of the desired project/repository on your computer, which syncs between the two locations (Remote-Local).

In other words, cloning a repository means downloading a complete copy of it to your computer. And what does a complete copy mean? Well, it means that after cloning a repository, you will have the entire history of the repository on your computer.

So why clone a repository you may ask? Cloning a project has many benefits as:

  • Browse the project's history, and see how it has evolved.
  • See the changes that have occurred in the code.
  • Know who has modified the code and when.
  • Access the branches of the project and create your own.
  • Start modifying the code, save the changes and add your work to the existing one.

And all this without the need to be connected to the internet. We will only need an internet connection when we want to "share" our work with someone else, or we want to upload our work to GitHub.

Cloning Thing GIF

In the following section, we will dive in on more detailed examples of how to clone a github repository and also how to fork any github repository.

Steps to Clone a GitHub Repository (Using the terminal)

For this example, we will clone one of 4Geeks popular repositories, that is 4Geeks react-flask-hello. The steps to clone this repository are as follows:

  1. Determine or locate where you want to clone the desired repository Locate the folder on your computer where you want to save the repository, or you can create a new one. Let’s say we want to save our repository in a folder called my-first-cloned-repo as shown below.

Locating Folder

  1. Open the terminal You can use the Git Bash terminal or any IDE (Integrated Development Environment) or Code Editor terminal. With the terminal opened, input cd and add/copy the directory/folder location/path. Since we want to save the repository in our folder my-first-cloned-repo, let's copy the folder's path C:\Users\rafam\Programming Projects\my-first-cloned-repo and paste it on the terminal, you can also drag and drop the folder on the terminal and press enter
1rafam@LAPTOP-LLV85FV6 MINGW64 ~ 2$ cd 'C:\Users\rafam\Programming Projects\my-first-cloned-repo' 3 4rafam@LAPTOP-LLV85FV6 MINGW64 ~/Programming Projects/my-first-cloned-repo
  1. Go to the 4Geeks react-flask-hello repository in GitHub. Once you are located in the Github repository, you need to click the Code button to display the clone options and then click the Copy button which is highlighted (shown below) and next to the repo URL:

4Geeks Repo Example Pic 1

4Geeks Repo Example Pic 2

  1. Go to the terminal and use the git clone command by typing git clone along with the copied URL
1rafam@LAPTOP-LLV85FV6 MINGW64 ~ 2$ cd 'C:\Users\rafam\Programming Projects\my-first-cloned-repo' 3 4rafam@LAPTOP-LLV85FV6 MINGW64 ~/Programming Projects/my-first-cloned-repo 5$ git clone https://github.com/4GeeksAcademy/react-flask-hello.git
  1. Press Enter and the repository will be cloned
1rafam@LAPTOP-LLV85FV6 MINGW64 ~ 2$ cd 'C:\Users\rafam\Programming Projects\my-first-cloned-repo' 3 4rafam@LAPTOP-LLV85FV6 MINGW64 ~/Programming Projects/my-first-cloned-repo 5$ git clone https://github.com/4GeeksAcademy/react-flask-hello.git 6 7Cloning into 'react-flask-hello'... 8remote: Enumerating objects: 1024, done. 9remote: Counting objects: 100% (33/33), done. 10remote: Compressing objects: 100% (22/22), done. 11Receiving objects: 99% (1014/1024), 6.82 MiB | 6.79 MiB/seused 991 12Receiving objects: 100% (1024/1024), 8.86 MiB | 7.31 MiB/s, done. 13Resolving deltas: 100% (521/521), done.

It is important to understand that you can clone any repository not only from GitHub but from any other site if you have the git URL. Remember that you clone a repository with the git clone <url> command.

Clone vs Fork

The difference between forking and cloning a project/repository really comes down to how much control a developer is allowed to have over a given repository.

By Forking, you can make your own copy of a repository somewhere else (for example, GitHub). Owning a copy of the repository means that you can make changes to it without affecting the original repository.

Cloning creates a local copy of a repository. Imagine doing that by downloading a repository to your computer's local storage. Clones have references to their original repositories, unlike forks.

Clone vs Fork

How to Fork a Repository

So you want to make your own copy of a repository, let's make a copy of the one that we cloned in the example above, 4Geeks react-flask-hello.

The steps to fork the repository are the following:

  1. Go to the GitHub repository 4Geeks react-flask-hello

  2. Click the Fork button located in the top right corner of the page

Fork Steps 2

  1. Then, an owner must be selected for the forked repository by clicking the Select an owner button and choosing the Repository name. You can also add a description (optional) to your fork if desired.

Fork Steps 3

  1. Below the description field, there is a checkbox (Copy the main branch only) that allows you to only copy the main branch, if you want to copy the whole repository with all of its branches, then this box should be unmarked.

Fork Steps 4

  1. You can now click Create Fork and it'll be done

Fork Steps 5

How to clone using the GitHub app instead of the terminal

You can also use the GitHub Desktop App to clone a repository to your computer, once you have downloaded the GitHub Desktop App here, and being signed to the GitHub website and Desktop App, then you can follow these steps:

  1. Go to the desired GitHub repository, and let's use the 4Geeks react-flask-hello repo again. Click on the Code button to display the options and proceed to click the Open with GitHub Desktop button.

GitHub App Steps 1

  1. The GitHub Desktop App will automatically open on your computer and a window called Clone a repository will be displayed. Here you can confirm the repository to be cloned, and you can change the local path where the repository will be saved by clicking the Choose... button, or you can just copy the path and paste it into the corresponding field.

GitHub App Steps 2

  1. You can now proceed to click the Clone button and the repository will be cloned in the desired path/directory

GitHub App Steps 3

The following video describes the step by step of everything that has been explained in this GitHub Clone Repository article: