Lesson Completion
Back to course

Open Source Contribution Flow

Intermediate
8 minutes4.8Git

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:

StepCommand / Action
1. ForkClick "Fork" on GitHub
2. Clone your forkgit clone <your-fork-url>
3. Add upstream remotegit remote add upstream <original-url>
4. Create branchgit checkout -b fix/typo-in-readme
5. Make changes + commitFollow project's commit conventions
6. Push to your forkgit push origin fix/typo-in-readme
7. Open PRPR from your fork → original repo
8. Address feedbackPush additional commits
9. Maintainer mergesSquash merge into upstream

Keeping your fork up-to-date:

ActionCommand
Fetch upstreamgit fetch upstream
Sync maingit rebase upstream/main
Push to forkgit 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

flowchart LR UPSTREAM["📦 Original Repo<br/>(upstream)"] -->|"1. Fork"| FORK["📦 Your Fork<br/>(origin)"] FORK -->|"2. Clone"| LOCAL["💻 Local"] LOCAL -->|"6. Push"| FORK FORK -->|"7. PR"| UPSTREAM UPSTREAM -->|"Sync"| LOCAL style UPSTREAM fill:#0f3460,stroke:#53d8fb,color:#53d8fb style FORK fill:#1a1a2e,stroke:#ffd700,color:#ffd700 style LOCAL fill:#1b2d1b,stroke:#53d8fb,color:#53d8fb

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

bash
# ─── 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-readme

Key Takeaways

  • Fork → Clone → Branch → PR is the standard open source workflow.
  • Add upstream remote to sync with the original repo.
  • Always branch from an up-to-date main for 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 upstream remote, 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 upstream remote? 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).

Topics Covered

WorkflowsOpen Source

Tags

#git#open-source#fork#contribution

Last Updated

2026-02-13