Learn GitHub
$ gh ghcollaboration.ghopensource

Collaboration and Open Source

6 learning objectives · 10 key terms · 7 commands · 3 diagrams · 5 quiz questions

$objectives

Collaboration and Open Source

Collaboration

Module 2 of 5 · lesson 7 in this module

What you'll be able to do

  • Fork a repository and explain how a fork differs from a clone
  • Add and manage an upstream remote so your fork stays current
  • Make a contribution on a branch and open a pull request from your fork
  • Find beginner-friendly projects to contribute to
  • Follow contribution guidelines, code of conduct and maintainer etiquette
  • Respond to review feedback without taking it personally
$concept

The idea, in plain language

You cannot push to a repository you do not own, and that is the whole reason forks exist. Forking copies someone else's repository into your own GitHub account, where you have full write access. Your fork keeps a link back to the original — conventionally named upstream — so you can pull in changes from a project you do not control. A clone is a copy on your laptop; a fork is a copy in your account. Contributing to a large project normally uses both: fork, clone your fork, branch, push to your fork, then open a pull request from your fork into the original.

Keeping the fork current is a habit, not an event. Fetch from upstream, merge or rebase main, push to your fork's main, then update your feature branches by rebasing them onto it. Do this before opening a pull request, and again if the maintainers merge other work while your pull request is in review. A stale fork is the most common reason a first contribution ends in a conflicted mess that nobody wants to resolve.

The human side matters just as much. Successful contributors read CONTRIBUTING.md before writing code, run the project's tests, keep each change small and single-purpose, and follow the issue they are fixing. Maintainers are usually volunteers working through a queue; a clear pull request with a good description is a gift, and a "why is this not merged yet?" comment is not. When review feedback arrives, treat it as information about the code, not a judgement of you — the reviewers are telling you exactly what the project expects, which is the fastest possible way to learn its standards.

$key terms

Key terms

Fork
A copy of someone else’s repository in your own GitHub account, with your own write access.
Clone
A copy of a repository on your computer.
upstream
The remote pointing at the original repository your fork came from.
origin
Here, your own fork — the remote you can push to.
Contribution guidelines
CONTRIBUTING.md: how the project wants changes proposed, tested and formatted.
Code of conduct
The behavioural rules for participating, with a route to report violations.
Maintainer
Someone with write access who reviews and merges contributions.
Good first issue
A label maintainers use to mark work suited to a newcomer.
Synchronising a fork
Pulling upstream changes into your fork’s main branch.
CLA / DCO
A contributor licence agreement or Developer Certificate of Origin some projects require, signed off with git commit -s.
$steps

How it works, step by step

  1. 1
    Read before you fork

    Open README.md, CONTRIBUTING.md and the code of conduct. Check whether issues marked good first issue exist, and whether the project asks for an issue before a pull request. Five minutes here saves a rejected contribution.

  2. 2
    Fork, then clone your fork

    Forking happens on GitHub; cloning happens on your machine. Clone the fork, not the original, because that is where you can push.

    fork and clonebash
    gh repo fork owner/project --clone
    cd project
  3. 3
    Add the original as upstream

    Your clone knows about your fork as origin. Add the original project as upstream so you can pull its changes.

    wire up upstreambash
    git remote add upstream https://github.com/owner/project.git
    git remote -v
    # origin    https://github.com/ada/project.git (fetch)
    # upstream  https://github.com/owner/project.git (fetch)
  4. 4
    Branch from an up-to-date main

    Sync first, then branch. A branch cut from a month-old main is the classic first-contribution mistake.

    sync, then branchbash
    git fetch upstream
    git switch main
    git merge --ff-only upstream/main
    git push origin main
    git switch -c fix/typo-in-readme
  5. 5
    Make the change the project asked for

    Follow the project's style, run its tests and linters, and keep the change narrowly scoped to the linked issue. Commit with a message matching the project's conventions.

    one scoped changebash
    git add README.md
    git commit -s -m "docs: fix broken install link"
    git push -u origin fix/typo-in-readme
  6. 6
    Open the pull request against upstream

    The base repository must be the original project, not your fork. Fill in the project's pull request template, link the issue, and say what you tested.

    open the PRbash
    gh pr create --repo owner/project --base main --head ada:fix/typo-in-readme
  7. 7
    Respond, iterate, and thank the reviewer

    Push fixes as new commits on the same branch, reply to each comment, and resolve discussions once handled. If the maintainers are slow, wait — a polite nudge after a couple of weeks is fine; a daily ping is not.

    keep the branch currentbash
    git fetch upstream
    git rebase upstream/main
    git push --force-with-lease origin fix/typo-in-readme
$commands

Commands worth memorising

Every block below is copy-ready — use the Copy button, then paste it into your terminal. Expected output is shown underneath so you know what “working” looks like.

fork and clonebash
gh repo fork owner/project --clone
Output
✓ Created fork ada/project
Cloning into 'project'...

Creates your fork and clones it with origin pointing at your copy.

add upstreambash
git remote add upstream https://github.com/owner/project.git

The original repository. Fetch from it, never push to it.

sync your forkbash
git fetch upstream
git switch main
git merge --ff-only upstream/main
git push origin main
Output
Updating 3f9a1c2..8c1d2ab
Fast-forward
 README.md | 4 ++--

--ff-only refuses to invent a merge commit if your main diverged — which should never happen on a fork.

update your branchbash
git rebase upstream/main

Replays your contribution on top of the newest upstream code. Resolve any conflicts locally, then force-push with --force-with-lease.

safe force-pushbash
git push --force-with-lease origin fix/typo-in-readme

Refuses if someone else pushed to the branch since your last fetch. Always prefer this over plain --force.

open a PR from your forkbash
gh pr create --repo owner/project --base main --head ada:fix/typo-in-readme --title "docs: fix broken install link"
Output
https://github.com/owner/project/pull/4127

Note the --head owner:branch form — that is how you name a branch on a fork.

check the issue firstbash
gh issue list --repo owner/project --label "good first issue" --limit 10
Output
4096  Document the --json flag for list commands    good first issue
4088  Add a test for empty input              good first issue

Find work the maintainers have explicitly marked as suitable for newcomers.

$diagrams

Workflow diagrams

Diagram 1The open-source contribution loop

Three copies of the same repository are in play: the original, your fork, and your laptop. Knowing which one each command talks to is the whole skill.

Reading the diagram
  1. Fork the upstream repository into your own account.
  2. Clone your fork, and add upstream so you can pull the original’s changes.
  3. Cut a feature branch and make one scoped change.
  4. Push to your fork and open a pull request whose base is the upstream repository.
  5. Iterate on review feedback by pushing more commits, then rebase once the maintainers have merged other work.
  6. When it is merged upstream, sync your fork and delete the branch.
Diagram 2Which copy does each command talk to?

Almost every first-time contribution problem is a command aimed at the wrong copy.

Reading the diagram
  1. Fetch and rebase from upstream; push only to origin.
  2. Branch and commit locally, then push the branch to your fork.
  3. Open the pull request with the base repository set to the original project.
Diagram 3What maintainers want from a contribution

The technical work is half of it; the other half is making the change easy to accept.

Reading the diagram
  1. Preparation (reading the guidelines, one scoped change) does more for merge speed than clever code.
  2. Communication keeps a contribution alive: reply, iterate, and be explicit about what you changed.
$example

Worked example

A complete first contribution to somebody else’s project, from fork to merge.

contributing a documentation fixbash
gh repo fork owner/project --clone
cd project
git remote add upstream https://github.com/owner/project.git

git fetch upstream
git switch main
git merge --ff-only upstream/main
git push origin main

git switch -c docs/fix-install-link
# ... fix the broken link in README.md ...
git add README.md
git commit -s -m "docs: fix broken install link"
git push -u origin docs/fix-install-link

gh pr create --repo owner/project \
  --title "docs: fix broken install link" \
  --body "The npm install link 404s. Points at the current package page. Closes #4096."

# maintainer merges it; sync up afterwards
git switch main
git fetch upstream
git merge --ff-only upstream/main
git push origin main
git branch -d docs/fix-install-link
Output
The change is merged upstream, your fork matches upstream exactly, and your board is clean.
1Forking into your own account is what gives you somewhere to push; cloning the fork rather than the original is the piece newcomers usually get wrong.
2Adding upstream lets you pull the original project’s changes into your fork — without it, your copy silently rots.
3The fetch/merge --ff-only/push sequence makes your fork’s main identical to upstream before you branch, so the diff stays minimal.
4The commit message follows the project’s conventions, and -s adds the sign-off that some projects require.
5The pull request names the base repository explicitly — this is what makes it a contribution to the project rather than to your own fork.
6Repeating the sync after the merge leaves your fork tidy and ready for the next contribution, with no stale branch lying around.
$use cases

Where you'll use it

▸Fixing a documentation typo or a broken link in a tool you use daily.
▸Adding a test that would have caught a bug you hit.
▸Implementing a small requested feature and getting it reviewed by experienced maintainers.
▸Learning a codebase by reading its contribution history and issue discussions.
▸Building a public track record of contributions that reviewers can evaluate.
▸Keeping a personal fork of an abandoned project alive with your own fixes.
$mistakes

Common mistakes

  • Cloning the original repository instead of your fork, then having nowhere to push.
  • Never adding an upstream remote, so your fork drifts months behind and the pull request is full of conflicts.
  • Opening a pull request from your fork’s main branch, which makes it hard to keep the branch updated and breaks your own main.
  • Submitting a large unsolicited refactor the project never asked for.
  • Ignoring CONTRIBUTING.md, so the pull request arrives in the wrong branch or without tests.
  • Using git push --force on a branch under review and wiping the reviewer’s line comments.
  • Commenting "any update?" every day on a pull request maintained by volunteers.
$best practices

Best practices

  • Read README, CONTRIBUTING and the code of conduct before writing any code.
  • Fork, clone your fork, add upstream, then branch from freshly synced main.
  • One contribution per branch, named after the issue.
  • Reuse the project’s pull request template and run its test suite locally.
  • Use git push --force-with-lease after a rebase, never a bare --force.
  • Reply to every review comment, and thank reviewers — they are the reason your change ships.
  • Sync your fork after the merge so the next contribution starts clean.
$exercise

Hands-on exercise

Ship one small contribution to a real project

Find something genuinely useful to fix — documentation counts, and is often the best place to start.

  1. Find a repository with a good first issue label or a documentation typo you have personally noticed.
  2. Read CONTRIBUTING.md and the code of conduct, and check whether the project wants an issue opened first.
  3. Fork and clone it, add upstream, sync main, then create a branch named after the issue you are fixing.
  4. Make the smallest change that solves it. Run the project’s tests or lint command and note the result.
  5. Commit following the project’s message conventions, push to your fork, and open a pull request against the upstream base branch using the project’s template.
  6. When a review arrives, reply to each comment, push any requested fix as a new commit, and reply again once it is done.

💡 Hint: Contributing to a project you already use is easier: you understand the problem, and the maintainers recognise the context in your pull request.

Done when: Your pull request is open against the upstream repository with a linked issue, the project’s tests pass, and you have replied to every review comment.

$quiz

Checkpoint quiz

0 of 5 answered · 0 correct

  1. Multiple choiceQ1

    What is the difference between forking and cloning?

  2. Command outputQ2

    What does this sequence accomplish?

    git fetch upstream
    git switch main
    git merge --ff-only upstream/main
    git push origin main
  3. TroubleshootingQ3

    After rebasing your branch you need to push it back to your fork. Which command is safest?

  4. True or falseQ4

    True or false: you can push directly to the original repository you forked from.

  5. Multiple choiceQ5

    What should you do before starting work on a large contribution to an unfamiliar project?

$summary

Module summary

  • Fork = a copy in your account; clone = a copy on your disk; contributing needs both.
  • Add the original project as upstream, fetch from it, and push only to origin.
  • Sync your fork before branching, and rebase your branch on upstream before opening the pull request.
  • Open the pull request against the upstream base branch, not just your fork.
  • --force-with-lease is the safe force-push after a rebase.
  • Read CONTRIBUTING.md, keep one change per pull request, reply to every comment, and be patient with volunteer maintainers.

Next up: Contribution flows teach you what to do when things go well. Module 8 covers what to do when they do not: recovering lost commits, undoing mistakes, and knowing which history-rewriting commands are safe on shared branches.

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books

Practice what you learned

Put the GitHub course to work: open one of the company-wise repositories and follow the workflow you just learned, branch to release.