Forks and contributing
Last updated
The Reyes family keeps the main Kusina, and only Lola Remy's children can push to it. Ana can still contribute: she forks it, works in her fork, and asks for her changes to be pulled in. This is also exactly how you contribute to open-source projects. In this lesson you'll keep a fork up to date and learn the etiquette that gets contributions accepted.
By the end of this lesson you can
- Explain a fork, and the upstream and origin remotes
- Keep a fork up to date with the project it came from
- Prepare a contribution the way a project asks: read CONTRIBUTING.md, start small, ask first
Three repositories
A fork is a copy of someone else's repository, made on the host, under your account. You can push to your fork; you can't push to theirs. So contributing involves three repositories:
git fetch upstream brings new commits to yougit clone (once) · ↑ git pushBy convention, your fork is origin (you cloned it) and the original project is upstream (you add it yourself).
Keep your fork up to date
The original project carries on without you. To bring its new commits into your fork:
git remote add upstream <its address>, once.git fetch upstream.git switch main, thengit merge upstream/main. If you never commit on main yourself, this is always a fast-forward.git pushto update your fork on the host.
Hosts also have a "Sync fork" button that does steps 2–4 on the host; you'd then pull.
- Check your remotes: only origin, your fork
- Add the family’s repository as
upstream(its address is in the note above) - Fetch upstream and merge its main into yours
- Push, so your fork is up to date too
- Read the CONTRIBUTING.md that just arrived
- Start your contribution on a new branch,
add-bibingka, and push it to your fork
Working folder
no changes
Staging area
nothing staged
Repository
10 commits on main
Remote
origin: example.com/ana/kusina.git · in step, as of your last fetch
You are in ~/kusina, your clone of your fork (https://example.com/ana/kusina.git). The family's repository is https://example.com/reyes-family/kusina.git, and it has changed since you forked it.
Commit graph
67e435dHEAD →mainorigin/main Cover the leche flan with foilba04ca2Add lumpiang shanghai recipe98a5edcAdd a script that builds the index paged078487Make the sinigang steps clearer145dc1eAdd pancit bihon recipe52d1f4dSay how much salt goes in the adobo1c17fadAdd a README9c53888Add leche flan recipe1f359a2Add sinigang recipe601c654Add adobo recipe
The last step would be a pull request on the host from ana:add-bibingka into reyes-family:main.
How projects want help
Every project has its own way of working. Before you start:
- Read
CONTRIBUTING.md(and the README). It says how to set up, how to run checks, what kind of pull requests are welcome, and how to name branches or write messages. - Read the code of conduct, often
CODE_OF_CONDUCT.md: how people are expected to treat each other. - Look at the issues. Many projects label beginner-friendly ones "good first issue". Comment that you'd like to try one before starting, so two people don't do the same work.
You can search the whole of GitHub for them: label:"good first issue" state:open in the search box, with Issues chosen.
- Issues. The search is showing issues, here over 484,000 of them. Code, repositories and pull requests are other kinds of result.
- Repository. Which project the issue belongs to. Look at it before choosing: is it active, is there a CONTRIBUTING.md?
- The label. The project’s maintainers marked this as a good place to start.
- Who and when. Brand-new issues may not be ready; ones with a recent reply from a maintainer usually are.
- Ask first for anything bigger than a typo. A five-minute question saves a week of work that doesn't fit.
- Keep it small. One fix or one feature per pull request. Small pull requests get reviewed; huge ones wait.
- Be patient and kind. Maintainers are often volunteers. A reply can take days. Answer review comments with changes or questions, not arguments.
Spot the trap: forty files nobody asked for
Ana wants to add one bibingka recipe to a big public recipe project. While she’s in there, she renames all the files to her style, reformats every recipe, and fixes some spelling. Her pull request changes forty files.
What happens if…
Check what you learned
Sources
Every command on this page behaves as these pages describe, and the sandbox prints what Git 2.55 prints. Hosting features (pull requests, protected branches) come from the host’s own documentation.
- GitHub Docs: About forks: what a fork is and how pull requests from forks work
- GitHub Docs: Syncing a fork: from the web, or with fetch and merge from upstream
- GitHub Docs: Setting guidelines for repository contributors: CONTRIBUTING.md
- Pro Git: Contributing to a Project: forked public projects, and small focused changes