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
- All files from the default branch
- The entire commit history
originremote already configured- Local tracking branches for all remote branches
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.
-
1Go to any GitHub repo and click Fork (top right). GitHub creates
your-username/repo. -
2Clone your fork to your machine:
git clone https://github.com/your-username/repo.git -
3Add the original repo as a second remote called
upstream:git remote add upstream https://github.com/original-owner/repo.git -
4Create a branch, make your changes, push to your fork, then open a Pull Request.
upstream
(original)
(original)
→ fork →
origin
(your fork)
(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
student@git-mastery: ~