How to create a pull request (PR) on GitHub

Key takeaways:

  • A pull request (PR) is a request to merge your changes into the main repository.

  • Ensure you have the proper permissions to create a pull request on the repository.

  • Navigate to the repository’s “Pull requests” tab and click “New pull request.”

  • Select the base branch (destination) and compare branch (source) for the PR.

  • The “Able to merge” message indicates no conflicts; “Can’t automatically merge” means there are merge conflicts that need resolution.

  • Use the GitHub CLI to create a PR after pushing changes to a new remote branch with gh pr create.

  • Include a title and description for the pull request using --title and --body flags in the GitHub CLI.

A pull request (PR) is a request to merge your changes into the main repository. When you’ve completed work on a branch and want your team to review and approve the changes before merging them into the main branch, you create a pull request. The team responsible for the main repository will review your changes and merge them if they consider them suitable. You can create a pull request in your project’s repository using GitHub.

Pull request roadmap
Pull request roadmap

Creating a pull request

Before we learn how to create pull requests, we need to make sure that we have the proper permissions on the repository where we’re creating them. For example, the process can be different for repositories that we only have write access to, as we won’t be able to open a pull request directly compared to repositories that we’re contributors to.

  • To create a pull request, first, go to the repository where you want to generate the pull request. Then, click the “Pull requests” option.

Pull requests menu
Pull requests menu
  • Then, click the “New pull request” button.

Creating a pull request
Creating a pull request
  • Then, you need to select the branch range and the destination repository. There will be two options: base and compare.

    • Base branch: This is the branch you want to merge your changes into. Often, it’s the main branch of the repository (like main or develop). By default, GitHub sets the base branch to the repository’s primary branch, but you can select any branch as the base.

    • Compare branch: This branch contains the changes you want to merge from. It’s the branch you worked on and where you made your updates. GitHub will compare this branch against the base branch to identify the changes you’ve made.

By default, the base of the pull request is set to the parent branch, but you can use the drop-down menu to select the branch you’d like to merge your changes into and the branch to which you want to compare your branch.

Merging branches
Merging branches
  • After selecting the branches, if you see the message “Able to merge” right next to the selected branches, it means no conflicts are preventing an automatic merge. However, if you see the message “Can’t automatically merge," it indicates that there are merge conflicts that need to be resolved. These conflicts won’t prevent you from creating a pull request, but they will hinder automatic merging if the pull request is accepted. Manual conflict resolution will be required in this case.

Using the GitHub CLI

In this case, we need to ensure that we’ve pushed our changes to a new branch on the remote repository. To do this, use the following commands in the terminal.

# check out the branch with your changes
git checkout -b <new-branch-name>
# push your changes to the remote repository
git push origin <new-branch-name>

Afterward, we can use the following command to create a pull request:

git pr create --base main --head <new-branch-name> --title "Your PR title" --body "You PR description"

In the command above,

  • --base: This specifies the branch we want to merge into.

  • --head: This specifies the branch we’re merging from.

  • --title and --body: These flags provide a title and description for the PR.

Conclusion

By understanding how to set up your branches and permissions, you can ensure your contributions are ready for review and potential integration into the main codebase. Whether you’re using the GitHub web interface or the GitHub CLI, knowing how to select the base and compare branches correctly, resolve any merge conflicts, and provide meaningful titles and descriptions will help your PRs get the attention they need. This approach enables smoother collaboration, code quality assurance, and the streamlined merging of changes into the main project.

Frequently asked questions

Haven’t found what you were looking for? Contact Us


How do I assign a PR on GitHub?

To assign a PR on GitHub, go to the pull request page, click the “Assignees” section, and select the user you want to assign.


How to allow public pull requests on GitHub?

To allow public pull requests on GitHub, ensure your repository is public and that contributors have forked the repository or created branches with appropriate access permissions.


Free Resources

Copyright ©2025 Educative, Inc. All rights reserved