💡 What is a fork? A fork is your own personal copy of someone else's repository on GitHub. It's how you contribute to open source — you work on your fork, then propose your changes to the original via a Pull Request.
Original Repo (upstream) Your Fork (origin)
github.com/owner/project → github.com/you/project
│ │
│ git clone ↓
│ Your Local Computer
│ │
└── sync updates ◄── git pull upstream main
│
make changes
git push origin
│
Open Pull Request ──► Original Repo
- Go to the original repo on GitHub (e.g.
github.com/owner/project) - Click the Fork button (top right)
- Choose your account — GitHub creates
github.com/you/project
# Clone YOUR fork (not the original!)
git clone git@github.com:YOUR_USERNAME/project.git
cd project# Add the original repo as a remote called "upstream"
git remote add upstream git@github.com:ORIGINAL_OWNER/project.git
# Verify both remotes exist
git remote -v
# origin git@github.com:YOUR_USERNAME/project.git (fetch)
# origin git@github.com:YOUR_USERNAME/project.git (push)
# upstream git@github.com:ORIGINAL_OWNER/project.git (fetch)
# upstream git@github.com:ORIGINAL_OWNER/project.git (push)💡 Naming convention:
origin= your fork,upstream= the original project.
⚠️ Never work directly onmainin your fork! Always create a new branch for your contribution.
# Make sure your main is up to date first (Step 6 explains how)
# Then create a feature branch
git checkout -b fix/typo-in-readme
# or
git checkout -b feat/add-dark-mode# Make your changes...
# Stage and commit
git add .
git commit -m "fix: correct typo in README introduction"
# Push your branch to YOUR fork
git push -u origin fix/typo-in-readmeThis is the step most beginners forget! If the original repo gets new commits while you're working, your fork goes out of date.
# Fetch the latest changes from the original repo
git fetch upstream
# Switch to your main branch
git checkout main
# Merge upstream's main into your local main
git merge upstream/main
# or (cleaner history):
git rebase upstream/main
# Push updated main to your fork
git push origin mainDo this regularly to avoid messy merge conflicts in your PR!
- Go to your fork on GitHub:
github.com/YOUR_USERNAME/project - GitHub will show a banner: "Compare & pull request" — click it
- Fill in:
- Title: Clear and descriptive (e.g. "Fix typo in README")
- Description: What you changed and why
- Click Create Pull Request
If the maintainer requests changes:
# Make the requested changes locally
git add .
git commit -m "fix: address review feedback"
# Push to the same branch — PR updates automatically!
git push origin fix/typo-in-readme# Sync your fork's main with upstream
git checkout main
git fetch upstream
git merge upstream/main
git push origin main
# Delete your feature branch (it's merged, no longer needed)
git branch -d fix/typo-in-readme
git push origin --delete fix/typo-in-readme| Fork | Clone | |
|---|---|---|
| Creates copy on GitHub | ✅ Yes | ❌ No |
| Creates copy locally | ❌ (clone separately) | ✅ Yes |
| Can push directly | Only to your fork | Depends on permissions |
| Used for | Contributing to others' repos | Working on your own repos |
# One-time setup
git remote add upstream git@github.com:owner/repo.git
# Before starting any new work
git fetch upstream
git checkout main
git merge upstream/main
git checkout -b my-new-feature
# After making changes
git add -p # Stage selectively
git commit -m "type: description"
git push -u origin my-new-feature
# After PR is merged
git checkout main
git merge upstream/main
git push origin main
git branch -d my-new-feature