Sub topic 9
Open the pull request
This chapter assumes you have already forked and cloned the repository, set up origin and upstream, and pushed a feature branch to your fork. If git push -u origin fix-readme-typo has not succeeded yet, go back to the previous chapter first.
What a pull request is
A pull request (PR) is a request on GitHub to merge one branch into another. It is not a Git feature. Git only knows about branches and commits. GitHub adds a page around them that holds the proposed diff, a discussion thread, automated check results, and the maintainers' approval.
When you contribute to a project you cannot write to, the PR connects two repositories. The head is your branch on your fork. The base is the branch on the upstream repository that you want your change merged into, usually main.
Open it from the website
After you push, GitHub often shows a yellow banner on your fork's page that says your branch had recent pushes, with a Compare & pull request button. If the banner is missing, open the Pull requests tab of the upstream repository and choose New pull request. Then choose compare across forks.
Before you submit, check the four dropdowns at the top of the page:
| Field | Should be |
|---|---|
| base repository | the original project, `ORIGINAL-OWNER/REPO` |
| base | the branch the project merges into, usually `main` |
| head repository | your fork, `YOUR-USERNAME/REPO` |
| compare | your feature branch, for example `fix-readme-typo` |
Read the Files changed tab before you submit. It shows what reviewers will see. Stray whitespace edits, debug output, or unrelated files are easier to remove now than after review starts.
Fill in the title and description
The title should say what the change does, in the same style as your commit message: "Fix typo in README installation section". The description should explain why the change is needed and how you checked it. If the project has a PR template, GitHub fills it in for you. Complete every section instead of deleting it. The next chapter covers descriptions in more detail.
If the change addresses an issue, add a line such as Fixes #123 to the description. When the PR is merged, GitHub closes that issue automatically.
Open it with the GitHub CLI
If you use the GitHub CLI (gh), you can open the PR from the branch you are on:
gh pr create --title "Fix typo in README installation section" --body "Corrects a misspelled command in the install steps."Inside a fork, gh targets the upstream repository by default. It will prompt you to confirm the push destination if your branch has not been pushed yet.
Draft pull requests
If your work is not ready for review, open a draft PR. On the website, use the arrow next to the green button and choose Create draft pull request. With the CLI, add --draft. Drafts cannot be merged, and they tell maintainers not to review yet. When you are ready, click Ready for review.
Common mistakes
- Wrong base. Opening the PR against your own fork's
maininstead of upstream. Check the base repository dropdown. - Wrong branch. Opening a PR from your fork's
main. This mixes unrelated changes into the PR and makes syncing harder later. Always use a feature branch. - Several changes in one PR. Reviewers can't approve half of a PR. Keep each PR to one purpose.
Exercise
You opened a PR and then noticed a typo in one line of your change. Do you need to close the PR and open a new one? What do you do instead?
Show answer
No. Fix the typo on the same feature branch, commit it, and run git push origin your-branch-name. The open PR updates with the new commit, because the PR tracks the branch and not a single snapshot.