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
(upstream)
(origin)
1. Fork the original repo → 2. Clone your fork → 3. Make changes → 4. Create Pull Request to original
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.
After forking, you'll be taken to your copy: https://github.com/your-username/original-repo-name
Now you have a fork on GitHub, but you need it locally to work.
git clone https://github.com/your-username/repo-name.gitCloning into 'awesome-project'...
remote: Enumerating objects: 123, done.
Then cd repo-name to enter the folder.
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 -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)
origin is yours to push.Before editing, create a branch. This keeps your changes organized and makes PRs cleaner.
git checkout -b my-feature-branchSwitched to a new branch 'fix-typo-in-readme'
Now make your changes (edit files, add new ones, etc.).
After editing, commit and push to your fork (origin).
git add . git commit -m "fix typo in README" git push origin my-feature-branch* [new branch] fix-typo-in-readme -> fix-typo-in-readme
Now your branch with changes is visible on your GitHub fork.
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".
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 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-branch → git merge main → git push origin my-branch.
Remote repositories summary
| Remote name | Points to | Permissions |
|---|---|---|
origin | Your fork (on GitHub) | Read/Write (you can push) |
upstream | Original repository | Read-only (you can pull, but not push) |
Fork & PR FAQ
upstream remote, then git checkout main, git pull upstream main, and git push origin main. This updates your fork's main.
Now you're ready to contribute to the world of open source. Fork, fix, PR!