Skip to main content

Merging a pull request

Merge pull requests into the upstream branch, choose merge methods, and meet repository requirements like reviews or status checks.

Tool navigation

About pull request merges

Merge a pull request when the proposed changes are ready and any repository requirements are satisfied. You can't merge a draft pull request.

Repository rules or branch protection may require reviews, status checks, or an up-to-date branch before merging. See About protected branches.

As an alternative to branch protection rules, you can create rulesets. Rulesets have a few advantages over branch protection rules, such as statuses, and better discoverability without requiring admin access. You can also apply multiple rulesets at the same time. For more information, see About rulesets.

You can configure a pull request to merge automatically when all merge requirements are met. For more information, see Automatically merging a pull request.

If the base branch requires a merge queue, the available merge options differ from those described here. See Merging a pull request with a merge queue.

If the pull request has merge conflicts, or if you want to test changes first, check out the pull request locally.

The repository may automatically delete the head branch after merging. See Managing the automatic deletion of branches.

Note

If you delete a head branch after its pull request has been merged, GitHub checks for any open pull requests in the same repository that specify the deleted branch as their base branch. GitHub automatically updates any such pull requests, changing their base branch to the merged pull request's base branch.

Pull requests use the --no-ff option, except squashed or rebased pull requests, which use fast-forward merging.

You can link a pull request to an issue to show that a fix is in progress and automatically close the issue when the pull request is merged. For more information, see Linking a pull request to an issue.

If you don't want to merge the changes, you can close the pull request.

Merging a pull request

  1. Under your repository name, click Pull requests.

  2. In the "Pull Requests" list, click the pull request you want to merge.

  3. Scroll down to the bottom of the pull request. Depending on the merge options enabled for your repository, choose a merge method:

    Note

    Rebase and merge will always update the committer information and create new commit SHAs. See About pull request merges.

  4. If prompted, type a commit message, or accept the default message.

    For information about the default commit messages for squash merges, see Pull request merges.

  5. If you have more than one email address associated with your account on GitHub, click the email address drop-down menu and select the email address to use as the Git author email address. Only verified email addresses appear in this drop-down menu. If you enabled email address privacy, then a no-reply will be the default commit author email address. For more information about the exact form the no-reply email address can take, see Setting your commit email address.

    Screenshot of a GitHub pull request showing a dropdown menu with options to choose the commit author email address. octocat@github.com is selected.

    Note

    The email selector is not available for rebase merges, which do not create a merge commit. For squash merges, the email selector is only shown if you are the pull request author and you have more than one email address associated with your account.

  6. Click Confirm merge, Confirm squash and merge, or Confirm rebase and merge.

  7. Optionally, delete the branch. This keeps the list of branches in your repository tidy.

Note

To learn more about GitHub CLI, see About GitHub CLI.

To merge a pull request, use the gh pr merge subcommand. Replace pull-request with the number, URL, or head branch of the pull request.

gh pr merge PULL-REQUEST

Follow the interactive prompts to complete the merge. See Pull request merges.

Alternatively, you can use flags to skip the interactive prompts. For example, this command squashes the commits into a single commit with the commit message "my squash commit", merges the squashed commit into the base branch, and then deletes the local and remote branch.

gh pr merge 523 --squash --body "my squash commit" --delete-branch

Further reading