The Hook (The "Byte-Sized" Intro)
You want to contribute to an open source project. You can't push to their repo. So you fork it — creating your own copy. You make changes in your fork, then open a pull request back to the original. The maintainers review, request changes, and eventually merge. This fork-and-PR model powers almost all open source on GitHub.
📖 What is the Open Source Contribution Flow?
The standard fork → clone → branch → PR workflow used by open source projects to accept contributions from external developers.
Conceptual Clarity
The complete flow:
| Step | Command / Action |
|---|---|
| 1. Fork | Click "Fork" on GitHub |
| 2. Clone your fork | git clone <your-fork-url> |
| 3. Add upstream remote | git remote add upstream <original-url> |
| 4. Create branch | git checkout -b fix/typo-in-readme |
| 5. Make changes + commit | Follow project's commit conventions |
| 6. Push to your fork | git push origin fix/typo-in-readme |
| 7. Open PR | PR from your fork → original repo |
| 8. Address feedback | Push additional commits |
| 9. Maintainer merges | Squash merge into upstream |
Keeping your fork up-to-date:
| Action | Command |
|---|---|
| Fetch upstream | git fetch upstream |
| Sync main | git rebase upstream/main |
| Push to fork | git push origin main |
Real-Life Analogy
Contributing to open source is like suggesting edits to a published book. You photocopy the chapter (fork), write your edits (branch), and submit them to the author (PR). The author reviews and decides whether to include them in the next edition.
Visual Architecture
Why It Matters
- Access control: Contributors can't push to the original repo.
- Quality: All changes go through maintainer review.
- Traceability: Every contribution is a PR with context and discussion.
- Safety: Forks are sandboxed — experiments don't affect the original.
Code
# ─── 1. Fork: click "Fork" on GitHub ───
# ─── 2. Clone your fork ───
git clone https://github.com/YOUR-USER/project.git
cd project
# ─── 3. Add upstream remote ───
git remote add upstream https://github.com/ORIGINAL-OWNER/project.git
git remote -v
# origin https://github.com/YOUR-USER/project.git (fetch)
# upstream https://github.com/ORIGINAL-OWNER/project.git (fetch)
# ─── 4. Create a branch ───
git checkout -b fix/typo-in-readme
# ─── 5. Make changes and commit ───
git add README.md
git commit -m "docs: fix typo in installation section"
# ─── 6. Push to your fork ───
git push origin fix/typo-in-readme
# ─── 7. Open PR: GitHub will show "Compare & pull request" ───
# ─── Keep fork in sync ───
git fetch upstream
git checkout main
git rebase upstream/main
git push origin main
# ─── Update PR branch with upstream changes ───
git checkout fix/typo-in-readme
git rebase main
git push --force-with-lease origin fix/typo-in-readmeKey Takeaways
- Fork → Clone → Branch → PR is the standard open source workflow.
- Add
upstreamremote to sync with the original repo. - Always branch from an up-to-date
mainfor your contribution. - Follow the project's CONTRIBUTING.md for commit style and process.
Interview Prep
-
Q: How do you contribute to an open source project on GitHub? A: Fork the repo, clone your fork, add the original as
upstreamremote, create a branch, make changes, push to your fork, and open a PR against the original repo. Follow the project's CONTRIBUTING.md. -
Q: What is the purpose of the
upstreamremote? A: It points to the original repository. You use it to sync your fork with the latest changes:git fetch upstream && git rebase upstream/main. Without it, your fork becomes outdated. -
Q: Why do open source projects use the fork model? A: Because external contributors can't push to the original repo. The fork model provides isolation (changes happen in the contributor's fork), review (all changes come as PRs), and safety (the original repo is protected).