Git & GitHub Course
Git & GitHub
/
Beginner

Cloning Repositories

Definition

Creating a local copy of a remote repository on your computer. When you clone a repository, you copy the entire project, including all its files, branches, and commits.

Explain Like I'm New

Downloading the project. You find a cool open-source project on GitHub, click the green 'Code' button, copy the URL, and run `git clone <URL>` in your terminal. You now have the entire project on your computer ready to run.

Real World Example

You buy a new laptop. You install VS Code, open the terminal, and `git clone` all your personal projects from GitHub onto the new machine.

Common Use Cases

  • •Setting up local environments
  • •Reviewing other people's code locally

Terminal Output

bash / terminal
# 1. Basic Clone (Creates a folder with the repo's name) $ git clone https://github.com/facebook/react.git # 2. Clone and give the folder a custom name $ git clone https://github.com/facebook/react.git my-react-experiment # 3. Clone ONLY a specific branch (Saves massive download time on huge repos!) $ git clone -b feature-xyz --single-branch https://github.com/user/repo.git # 4. Clone without the entire git history (Shallow clone - extremely fast!) $ git clone --depth 1 https://github.com/user/repo.git

Interview Questions

basic

  • What is the difference between Forking and Cloning?

intermediate

  • Can you clone a private repository?

Flash Cards

Question

Fork vs Clone?

Click to reveal answer
Answer

Forking is a Cloud-to-Cloud copy (GitHub to GitHub). Cloning is a Cloud-to-Local copy (GitHub to your Laptop).

Question

Clone private?

Click to reveal answer
Answer

Yes, but ONLY if you have been granted explicit access to it, and you authenticate your terminal (via SSH keys or Personal Access Tokens) to prove who you are.