Forking Repositories and Cloning to Local Machine (git clone)0%
Creating and Managing Pull Requests (PRs) on GitHub

Forking Repositories and Cloning to Local Machine (git clone)

Beginner12 min read•Updated: Jul 11, 2026
Study MaterialsCheatsheet

Forking Repositories and Cloning to Local Machine (git clone)

Two of the most frequent ways to obtain code on GitHub are cloning and forking. While both involve copying a repository, they serve distinct roles in open-source development and enterprise collaboration.


1. Cloning a Repository: git clone

Cloning downloads an entire existing Git repository from a remote server (like GitHub) to your local computer:

  • It downloads all files, directories, commits, and branches.
  • It automatically configures the remote alias named origin pointing back to the cloned URL.
  • It automatically checks out the default branch (main).
Bash / Terminal
# Clone using SSH URL (Recommended)
git clone git@github.com:facebook/react.git
 
# Or clone using HTTPS URL
git clone https://github.com/facebook/react.git

Cloning into a Custom Directory Name:

By default, Git creates a folder named after the repository (react). You can specify a custom directory name as the last argument:

Bash / Terminal
git clone git@github.com:facebook/react.git my-react-study

Shallow Cloning (--depth 1):

For massive repositories (like Linux or Chromium) with 15 years of history, downloading every commit can take hours and gigabytes of disk space. A shallow clone downloads only the latest snapshot:

Bash / Terminal
git clone --depth 1 https://github.com/torvalds/linux.git

2. Forking a Repository

What if you want to contribute to an open-source project (like vuejs/core or django/django), but you are not an employee and do not have write access to push commits to their repository? This is where Forking comes in!

Output
Original Upstream Repo Your Personal Fork on GitHub
[ github.com/facebook/react ] ----> [ github.com/sumit-msk/react ] (Your cloud copy)
|
git clone
|
v
Local Laptop [ D:/projects/react ]

What is a Fork?

  • A Fork is a complete copy of a repository that lives entirely on your personal GitHub account.
  • Because it lives under your account, you have full administrative write and push access to it.
  • You make your changes, commit them to your fork, and then submit a Pull Request (PR) back to the original author's repository.

How to Fork a Repo:

  1. 1
    Navigate to the public repository on GitHub (e.g., github.com/msk-institute/python-cheatsheet).
  2. 2
    In the top-right corner of the page, click the Fork button.
  3. 3
    Select your personal account and click Create fork.
  4. 4
    GitHub duplicates the repository under your username in seconds!

3. Cloning vs. Forking: Quick Summary

Featuregit cloneGitHub Fork
Where it happensOn your local computer diskOn GitHub's cloud servers
Tool UsedGit command line (git clone)GitHub Web UI button
Permissions neededRead access to the repositoryRead access to the public repository
Primary purposeGet files onto your laptop to run and developCreate a personal cloud copy to propose contributions to upstream repos

Interactive Quiz

Practice Quiz

Question 1
What does git clone do?
Question 2
Where does a "Fork" reside?
Question 3
Why do developers fork open-source repositories before making contributions?
Question 4
Which command downloads only the single most recent commit snapshot of a repository, skipping historical commits?
Question 5
When you clone a repository with git clone <url>, what name does Git automatically assign to the remote bookmark?
Next Lesson

Creating and Managing Pull Requests (PRs) on GitHub

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

PrevNext