What a pull request does and when to use one

A pull request is how you propose changes to a repository on GitHub. You write code in your own branch, then ask the repository owner or maintainers to review it and merge it into the main codebase. The pull request itself is not the code — it is a conversation about the code, where reviewers can comment on specific lines, suggest changes, and decide whether to accept or reject your work.

You create a pull request when you have finished work on a feature or bug fix and want someone else to look at it before it goes live. This works whether you are contributing to an open-source project, collaborating with teammates, or working on your own repository with other people.

The basic flow is: you fork or clone the repository, create a new branch, make your changes, push that branch to GitHub, then open a pull request from your branch into the main branch (usually called main or master).

Key Takeaways

  • You must push your branch to GitHub before you can open a pull request — the pull request compares two branches that both exist on GitHub's servers.
  • The pull request title and description should explain what changed and why, because reviewers will read this before looking at the code itself.
  • GitHub shows you a diff (the line-by-line differences) automatically, so reviewers can see exactly what you added, removed, or modified.
  • You can add reviewers, link to related issues, and set labels before you create the pull request, or add them afterward.

Create a branch and make your changes

Before you open a pull request, you need a branch that contains your work. If you are working on a repository you own or have write access to, create a new branch from the command line using git checkout -b branch-name. Replace branch-name with something short and descriptive — for example, fix-login-bug or add-dark-mode.

If you are contributing to a repository you do not own, fork it first (click the Fork button on the repository page), then clone your fork to your computer. Create your branch inside that clone. This way you have your own copy of the entire repository to work in.

Make your changes in your editor, test them locally, and commit them to your branch using git add and git commit. Write clear commit messages that explain what each commit does — reviewers will see these messages in the pull request.

Push your branch to GitHub

Once your commits are ready, push your branch to GitHub using git push origin branch-name. This uploads your branch to GitHub's servers so that it exists there alongside the main branch. If this is the first time you are pushing this branch, Git will ask you to set the upstream branch — follow the command it suggests, or use git push -u origin branch-name.

After you push, go to the repository page on GitHub. You should see a yellow banner near the top that says something like "Your recently pushed branches" with a button that says "Compare & pull request". Click that button to start creating your pull request. If you do not see the banner, click the "Pull requests" tab at the top of the repository page, then click the green "New pull request" button.

Choose the branches and write your description

GitHub will show you a page titled "Comparing changes". At the top, you will see two dropdown menus: one for the base branch (the branch you want to merge into, usually main) and one for the compare branch (your branch with the new code). Make sure these are correct — base should be the main repository's main branch, and compare should be your branch.

Below that, you will see a preview of all the changes: files added, removed, or modified, with a diff showing the exact lines that changed. Review this to make sure you are submitting what you intended.

Scroll down and fill in the pull request title and description. The title should be one line and say what you did — for example, "Fix login form validation error" or "Add user profile page". The description should explain why you made these changes and any context a reviewer needs to understand them. Mention if this closes an issue by typing "Closes #123" (replace 123 with the issue number), and GitHub will automatically link them.

Add reviewers, labels, and other details

On the right side of the pull request form, you will see options to add reviewers, assign the pull request to yourself or someone else, add labels, and link to a project. You can fill these in now or add them after you create the pull request — either way works.

If you know who should review your code, click "Reviewers" and select their names. If you are not sure, leave it blank and the repository maintainers will assign reviewers themselves. Labels help organize pull requests — common ones include "bug", "feature", "documentation", or "needs review". Projects link the pull request to a GitHub project board if your team uses one for tracking work.

Create the pull request

Once your title and description are filled in, click the green "Create pull request" button at the bottom of the form. GitHub will create the pull request and take you to its page. You will see your description, the list of commits, and the full diff of all changes.

From here, reviewers can comment on your code, request changes, or approve it. You can push new commits to your branch at any time, and they will automatically appear in the pull request — you do not need to create a new one. When reviewers are satisfied, someone with write access to the repository will click "Merge pull request" to combine your changes into the main branch.

Respond to review feedback

If a reviewer requests changes, you do not need to close the pull request and start over. Instead, make the changes they asked for in your local branch, commit them, and push to the same branch. The new commits will appear in the pull request automatically, and the reviewer will see them.

You can reply to comments directly on the pull request page. Click the reply box under a comment to explain your thinking or ask a question. Once you have addressed all feedback and the reviewer approves, the pull request is ready to merge.

Frequently Asked Questions

What if I need to update my pull request after I create it?

Push new commits to the same branch. They will appear in the pull request automatically — you do not need to create a new one. If you need to change your title or description, click the pencil icon next to the title on the pull request page.

Can I create a pull request if I do not have write access to the repository?

Yes. Fork the repository first, make your changes in your fork, then create a pull request from your fork into the original repository. The repository owner will see it and can review and merge it if they choose.

What does the diff show in a pull request?

The diff shows every line you added (in green), removed (in red), or modified. You can click the comment icon next to any line to leave feedback on that specific part of the code. Reviewers use this to point out problems or ask questions about your changes.

Do I have to add reviewers when I create a pull request?

No. You can create a pull request without assigning reviewers, and the repository maintainers will assign them or review it themselves. If you know who should look at your code, adding them speeds up the review process.

What happens if my pull request has conflicts with the main branch?

GitHub will tell you if your branch conflicts with the base branch — this means both branches changed the same lines. You will need to resolve these conflicts in your local branch, commit the fix, and push again. GitHub will show you which files have conflicts and help you fix them.