Master the fork-branch-PR workflow used by open-source projects worldwide.
10 min readNearly every open-source project uses the same collaboration model: fork the repo, create a branch, make changes, push, and open a pull request. This path walks you through each step.
Create your own copy of the project on GitHub.
Clone your fork locally and set up the upstream remote.
Never work on main. Always create a descriptive branch name.
Write atomic commits with clear, conventional messages.
Keep your fork up to date to avoid merge conflicts.
Push your branch and create a PR with a clear description.
Click the "Fork" button on the GitHub repository page. This creates a copy under your GitHub account that you have full write access to.
# Clone your fork
git clone https://github.com/YOUR-USERNAME/project.git
cd project
# Add the original repo as HL0
git remote add upstream https://github.com/ORIGINAL-OWNER/project.git
# Verify remotes
git remote -v
# origin https://github.com/YOUR-USERNAME/project.git (fetch)
# upstream https://github.com/ORIGINAL-OWNER/project.git (fetch)# Always branch from the latest upstream main
git fetch upstream
git checkout -b fix/issue-42-memory-leak upstream/mainNever commit directly to main
# Stage specific files (not git add .)
git add src/utils/cache.ts src/utils/cache.test.ts
# Write a conventional commit message
git commit -m "fix: resolve memory leak in cache invalidation
Closes #42. The cache was holding references to expired entries
because the cleanup timer was using setInterval instead of
setTimeout with recursive scheduling."# Fetch latest changes from the original repo
git fetch upstream
# Rebase your branch on top of upstream/main
git rebase upstream/main
# If there are conflicts, resolve them, then:
git add .
git rebase --continue# Push your branch to your fork
git push origin fix/issue-42-memory-leakThen go to the original repository on GitHub. You'll see a banner suggesting you open a pull request. Click it and fill in the PR template.
When contributing to open source, where should you create your feature branch from?
On this page