Module 09 of 10 · clone · fork · upstream

Cloning & Forking

git clone — Copy a Repository

Cloning downloads an entire repository (all files, all history) to your local machine:

git clone https://github.com/user/repo.git

This creates a folder named repo in your current directory, pre-configured with origin pointing back to GitHub.

Clone into a custom folder name:

git clone https://github.com/user/repo.git my-custom-folder

What Cloning Gives You

Forking — Contributing to Open Source

If you want to contribute to a repository you don't own, you can't push to it directly. Instead you fork it — create your own copy of the repo under your GitHub account.

  1. 1
    Go to any GitHub repo and click Fork (top right). GitHub creates your-username/repo.
  2. 2
    Clone your fork to your machine: git clone https://github.com/your-username/repo.git
  3. 3
    Add the original repo as a second remote called upstream: git remote add upstream https://github.com/original-owner/repo.git
  4. 4
    Create a branch, make your changes, push to your fork, then open a Pull Request.
upstream
(original)
→ fork →
origin
(your fork)
→ clone →
local

Keeping Your Fork Up to Date

The original project may have new commits. Pull them into your local main, then push to your fork:

git fetch upstream
git switch main
git merge upstream/main
git push origin main
Clone vs Fork: Clone a repo you own or have write access to. Fork a repo you want to contribute to but don't own.

Simulator Challenges

Clone a simulated repo: git clone https://github.com/example/project.git
Add an upstream remote: git remote add upstream https://github.com/original/project.git
Check both remotes: git remote -v
Module 9 complete! You can now collaborate on any open-source project. One module left: Pull Requests!
student@git-mastery: ~