Forks & Pull Requests: contribute to any repository

Want to contribute to open source or collaborate on a project you don't own? Forks and pull requests are the answer. Learn how to fork, clone, create PRs, and keep your fork updated.

Fork + PR flow

Original repo
(upstream)
Your fork
(origin)
Pull Request

1. Fork the original repo → 2. Clone your fork → 3. Make changes → 4. Create Pull Request to original

Step 1: Fork a repository (one click)

Find any public repository on GitHub. In the top-right corner, click the "Fork" button. This creates a copy of the entire repo under your GitHub account.

Your fork is independent: You can commit, change branches, do anything – without affecting the original project. It's your playground.

After forking, you'll be taken to your copy: https://github.com/your-username/original-repo-name

Step 2: Clone your fork to your computer

Now you have a fork on GitHub, but you need it locally to work.

git clone https://github.com/your-username/repo-name.git
$ git clone https://github.com/yourname/awesome-project.git
Cloning into 'awesome-project'...
remote: Enumerating objects: 123, done.

Then cd repo-name to enter the folder.

Step 3: Add "upstream" remote (crucial!)

Your fork (origin) is a copy. The original repo is called upstream. Adding it lets you pull latest changes from the original.

git remote add upstream https://github.com/original-owner/original-repo.git
$ git remote add upstream https://github.com/facebook/react.git
$ git remote -v
origin https://github.com/yourname/react.git (fetch)
origin https://github.com/yourname/react.git (push)
upstream https://github.com/facebook/react.git (fetch)
upstream https://github.com/facebook/react.git (push)
Never push to upstream (you don't have permission anyway). Only origin is yours to push.
Step 4: Create a new branch (always!)

Before editing, create a branch. This keeps your changes organized and makes PRs cleaner.

git checkout -b my-feature-branch
$ git checkout -b fix-typo-in-readme
Switched to a new branch 'fix-typo-in-readme'

Now make your changes (edit files, add new ones, etc.).

Step 5: Commit and push to your fork (origin)

After editing, commit and push to your fork (origin).

git add .
git commit -m "fix typo in README"
git push origin my-feature-branch
$ git push origin fix-typo-in-readme
* [new branch] fix-typo-in-readme -> fix-typo-in-readme

Now your branch with changes is visible on your GitHub fork.

Step 6: Open a Pull Request

Go to your fork on GitHub. You'll often see a banner: "fix-typo-in-readme had recent pushes" with a "Compare & pull request" button. Click it.

Or go to "Pull requests" tab → "New pull request". Select:

  • base repository: original-owner/original-repo (the one you forked from)
  • base branch: main (or their default branch)
  • head repository: your-username/original-repo (your fork)
  • compare branch: your-feature-branch

Add a title and description explaining your changes, then click "Create pull request".

✅ Done! The maintainers of the original repo will see your PR, review, discuss, and eventually merge it.
Step 7: Keep your fork up to date

While your PR is open, or after it's merged, the original repo may get new commits. To update your fork:

git checkout main
git pull upstream main
git push origin main
$ git checkout main
$ git pull upstream main
$ git push origin main

This brings your local main and your fork's main in sync with the original project.

To update a feature branch, merge main into it: git checkout my-branchgit merge maingit push origin my-branch.

Remote repositories summary

Remote namePoints toPermissions
originYour fork (on GitHub)Read/Write (you can push)
upstreamOriginal repositoryRead-only (you can pull, but not push)

Fork & PR FAQ

What's the difference between fork and branch?
A fork is a server-side copy of the whole repository under your account. A branch is a lightweight pointer inside a single repository. Forks are used when you don't have write access; branches are for collaboration within the same repo.
Do I need to fork my own repository?
No. If you own the repo or have write access, you can work directly with branches and PRs without forking.
Can I have multiple forks of the same repo?
Yes, each GitHub user can fork a repo once. But you can have multiple clones locally from different accounts.
How do I sync my fork with the original after it's been updated?
Add the upstream remote, then git checkout main, git pull upstream main, and git push origin main. This updates your fork's main.
What if my PR has conflicts?
Resolve them locally: sync main from upstream, merge main into your branch, fix conflicts, commit, push. GitHub will update the PR automatically.
Can I open a PR from a branch that's not mine?
Yes, if you have permission to push to that branch (e.g., in a shared repository), you can create a PR between any branches.
How do I contribute to open source for the first time?
Find a project with "good first issue" labels. Fork, create a branch, fix the issue, push, and open a PR. Start with small docs fixes to get comfortable.
What is "upstream" and why do I need it?
Upstream is the original repository you forked from. You need it to pull the latest changes from the original project so your fork stays updated.
Can I delete my fork after PR is merged?
Yes, you can delete your fork. But you'll lose your copy and any branches. Many people keep it for future contributions.
What if the original repo is private?
You can only fork private repos if you're a collaborator and the repo allows forking. Usually private repos are not forkable by outsiders.
Is there a limit to number of PRs?
No, you can open as many PRs as you want. However, be respectful and don't spam.
Previous: Branches Next: Issues & labels

Now you're ready to contribute to the world of open source. Fork, fix, PR!