Skip to main content

Cloning a Repository

Once you have a repository on GitHub (either your own or a Fork you made), the next step is to bring that code onto your physical computer. This process is called Cloning.

When you clone a repository, you aren't just downloading the files; you are downloading the entire project history and setting up a connection between your computer and the cloud.

What happens during a Clone?

Unlike a simple "Download ZIP," git clone does three things automatically:

  1. Creates a folder with the project name.
  2. Downloads every version of every file in the project's history.
  3. Sets up a Remote called origin, which points back to GitHub so you can push and pull changes later.

How to Clone a Project

To clone a repository, you need its URL. You can find this on the main page of any GitHub repository.

Step 1: Get the URL

  1. Go to the repository on GitHub.
  2. Click the green <> Code button.
  3. Copy the HTTPS URL (it looks like https://github.com/user/repo.git).

Step 2: Run the Command

Open your terminal (or Git Bash) and type git clone followed by the URL you copied:

git clone https://github.com/codeharborhub/tutorial.git

Step 3: Enter the Project

After the download finishes, you must move into the new folder before you can start working:

cd tutorial

Comparison: Clone vs. Download ZIP

FeatureGit CloneDownload ZIP
FilesYesYes
HistoryYes (Every commit ever made)No (Only current files)
UpdatesEasy (git pull)Must download whole ZIP again
ContributionReady to Push/PRNot connected to Git

Common Use Cases

ScenarioWhat to do?
Joining a TeamGet the project URL from your lead and git clone it.
Switching PCsgit clone your own repo to your new laptop.
Learning Open SourceFind a cool repo, fork it, then clone your fork.

Cloning with VS Code

If you prefer using a visual tool instead of the terminal, you can clone directly inside Visual Studio Code:

  1. Open VS Code.
  2. Press Ctrl + Shift + P (or Cmd + Shift + P on Mac).
  3. Type Git: Clone and press Enter.
  4. Paste the GitHub URL and choose a folder on your computer. VS Code will handle the cloning process for you!

Important Note for Beginners

Only clone once. A common mistake is running git clone every time you want to work on a project.

  • Use git clone the first time you get the project.
  • Use git pull every time after that to get the latest updates.
tip

By default, Git clones the project into a folder named after the repository. If you want to name the folder something else, just add the name at the end:
git clone https://github.com/user/repo.git my-custom-folder-name