# Forking & Cloning

> Understanding the difference between server-side copies and local downloads.

Subject: Version Control | Lesson 26 of 29 | 6 min read
Interactive lesson: https://codewithanimation.in/git/forking-and-cloning
Previous: [Pull Requests](https://codewithanimation.in/git/pull-requests.md) | Next: [The Git Stash](https://codewithanimation.in/git/git-stash.md)

## Server vs Local Copies

**Forking:** A fork is a personal, server-side copy of another user's repository that lives on your GitHub account. It shares code and visibility settings with the original 'upstream' repository.

**Cloning:** A clone is a local copy of a repository that lives on your computer. Cloning downloads the files and history from GitHub to your local machine so you can develop.

## Why it matters

Web developers often want to contribute to open-source projects (like React or Next.js) where they do not have direct write/push permissions.

Forking gives them a personal copy of the project in the cloud where they have full read and write access. They can make changes safely, and then submit a Pull Request back to the original repository.

## How it works

**Forking (Server-Side):** Happens entirely on GitHub's servers. You click the 'Fork' button on the website, and GitHub instantly duplicates the project into your account.

**Cloning (Local):** Happens on your local machine. You run `git clone <url>` in your terminal. Git fetches the data from GitHub and creates a working directory on your hard drive.

## Common mistake: The Out-of-Sync Fork

The #1 misconception is believing that a fork stays automatically synced with the original repository.

A fork is just a snapshot in time. If the original repository is updated, your fork will immediately fall behind. You must manually sync your fork by fetching and pulling changes from the upstream repository.

## Tip: The Google Docs Mental Model

Think of **Forking** as clicking 'Make a Copy' of someone else's Google Doc so it appears in your own Google Drive.

Think of **Cloning** as downloading that Google Doc to your computer's hard drive to edit it offline.

Pro Tip: After cloning your fork locally, add the original repo as an upstream remote (`git remote add upstream <url>`) to easily keep your fork updated.

## Try it: Trace a fork contribution

Follow a contribution from an upstream project through a fork and local clone.

The animation is on the lesson page and is not part of this text version: https://codewithanimation.in/git/forking-and-cloning

## Check yourself

### Question 1

What is the primary difference between a fork and a clone?

- A. A clone is a copy on GitHub servers, while a fork is a copy on your local machine.
- B. A fork creates a copy of a repository in your GitHub account, while a clone downloads a repository to your local computer.
- C. A fork is used for your own projects, while a clone is used for open-source projects.
- D. A clone keeps the repository's commit history, but a fork deletes it.

Correct answer: B

Forking is server-side duplication; cloning is downloading locally.

- Why not A: It is exactly the opposite.
- Why not C: You generally fork open-source projects.
- Why not D: Both preserve the entire commit history.

### Question 2

Why would a developer need to fork a repository instead of just cloning it?

- A. Because cloning is only for downloading single files, not entire projects.
- B. Because forks automatically sync with the original project every hour.
- C. Because they do not have write access to the original repository and want to propose changes via a Pull Request.
- D. Because you cannot use Git branches if you only clone a repository.

Correct answer: C

You need a fork to get a server-side copy where you have permission to push changes.

- Why not A: Cloning downloads the entire project.
- Why not B: Forks do NOT sync automatically. You must sync them manually.
- Why not D: You can use branches locally in a clone regardless of how you got it.

### Question 3

Which of the following commands is used to create a fork?

- A. git fork <url>
- B. git clone --fork <url>
- C. git branch new-fork
- D. You don't use a Git command; you create a fork via the GitHub website UI.

Correct answer: D

Forking is a platform-specific feature provided by Git hosting services like GitHub, not a native Git command.

- Why not A: There is no `git fork` command built into core Git.
- Why not B: This flag does not exist.
- Why not C: This creates a local branch, not a remote fork.

## Remember this

- Forking is copying a repo to your GitHub account.
- Cloning is downloading a repo to your local machine.
- Forks do not automatically stay synced.
- Forking is essential for contributing to open source.
