Forks and Contributing to Open Source
Contribute to projects you do not own: fork a repository, clone your fork, add the original as upstream, keep your fork in sync and open a pull request to the maintainers.
On this page 12 sections
Introduction
Contributing to open source is one of the best ways to learn, build a public track record and meet other developers — and many of the tools you use every day accept contributions from anyone. You cannot push to someone else’s repository, though. The solution is a fork: your own copy of their project on GitHub, from which you send them pull requests.
- What a fork is and how it differs from a clone.
- How to set up origin (your fork) and upstream (the original project).
- How to keep your fork up to date with the original.
- How to make a contribution and where to find beginner-friendly issues.
What Is a Fork?
A fork is a copy of a repository under your own GitHub account. You can push to your fork freely, and GitHub remembers which project it came from, so you can open pull requests back to the original. In this lesson Priya contributes to a community recipe collection, open-recipes/recipes, maintained by Ravi.
| Name | Where it lives | Who can push |
|---|---|---|
| upstream | github.com/open-recipes/recipes — the original project | Only the maintainers |
| origin | github.com/priya-sharma/recipes — Priya’s fork | Priya |
| local clone | Priya’s computer | Priya |
Fork and Clone
On the original repository’s page, click “Fork” in the top-right corner and create the fork under your account. Then clone your fork — not the original:
git clone https://github.com/priya-sharma/recipes.gitcd recipesClick Run to see what this code prints.
Add the Upstream Remote
The clone knows about your fork as origin. Add the original project as a second remote, conventionally named upstream:
git remote add upstream https://github.com/open-recipes/recipes.gitgit remote -vClick Run to see what this code prints.
You fetch from upstream to get the maintainers’ latest work, and push to origin, your fork.
Keep Your Fork in Sync
Projects keep moving. Since Priya forked, Ravi added a soup recipe. Her fork does not update itself, so before starting work she brings in the latest upstream changes:
git fetch upstreamClick Run to see what this code prints.
git merge upstream/mainClick Run to see what this code prints.
Her local main now matches the original project. Pushing it updates her fork on GitHub as well:
git push origin mainClick Run to see what this code prints.
GitHub also shows a “Sync fork” button on your fork’s page that updates its main branch from the original. You still need to pull afterwards to update your local copy.
Priya’s fork is three weeks old and the original project has moved on. She is on main in her clone. Which commands bring her main up to date with the original project?
Make Your Contribution
Always work on a branch, never directly on main. That keeps your main identical to upstream and lets you work on several contributions at once:
git switch -c add-masala-chai# ...create recipes/masala-chai.md...git add recipes/masala-chai.mdgit commit -m "Add masala chai recipe"Click Run to see what this code prints.
Push the branch to your fork:
git push -u origin add-masala-chaiClick Run to see what this code prints.
On GitHub, open your fork and click “Compare & pull request”. GitHub automatically sets the base to open-recipes/recipes main and the compare branch to your fork’s add-masala-chai. Describe your change, link the issue it solves, and create the pull request. If the maintainers ask for changes, commit and push to the same branch — exactly as in the previous lesson.
Put the steps of a first open-source contribution in order.
- Open a pull request to the original repository
- Create a branch, make the change and commit
- Fork the repository on GitHub
- Push the branch to origin (your fork)
- Clone your fork and add the original as upstream
- Sync main with git fetch upstream and git merge upstream/main
Finding a First Issue
- Many projects label beginner-friendly issues “good first issue” or “help wanted” — search for these labels on GitHub.
- Documentation fixes, typos and clearer error messages are real, welcome contributions and a great way to start.
- The firstcontributions/first-contributions repository on GitHub exists purely to practise this workflow safely.
- Contribute to tools you already use — you understand the problems, and maintainers value user perspective.
Open-Source Etiquette
- Read the project’s README and CONTRIBUTING file first; they explain how the maintainers want to receive changes.
- For anything bigger than a small fix, comment on the issue before you start, so nobody duplicates work and the maintainers can agree on the approach.
- Follow the project’s code style and keep the pull request focused on one change.
- Be patient and polite — most maintainers are volunteers. A friendly reminder after a week or two is fine.
- Check the project’s licence; by contributing, you agree to license your work under it.
Common Mistakes
- Cloning the original repository instead of your fork, then being unable to push.
- Committing to your fork’s main branch, so it drifts away from upstream.
- Forgetting to sync with upstream before starting, then hitting conflicts in the pull request.
- Opening a large, unannounced pull request that the maintainers did not ask for.
Frequently Asked Questions
A clone is a copy on your computer. A fork is a copy on GitHub, under your account. In this workflow you have both: you fork on GitHub, then clone your fork.
No. Team members with write access usually push branches directly to the main repository and open pull requests from there. Forks are for contributors without write access.
It can. Merged pull requests show real collaboration skills — reading unfamiliar code, following conventions and responding to review — which are exactly what employers look for.
Key Takeaways
- A fork is your own copy of someone else’s repository on GitHub.
- Clone your fork (origin) and add the original as upstream.
- Sync with git fetch upstream and git merge upstream/main, then push to origin.
- Work on a branch, push it to your fork, and open a pull request to the original project.
- Read CONTRIBUTING, start small and communicate with maintainers.
Summary
You can now contribute to any public project on GitHub. Next, two everyday tools: stash, for parking unfinished work when something urgent comes up, and tags, for marking releases like version 1.0.