Skip to main content

Merging a pull request

Merge a pull request into the upstream branch when work is completed. Anyone with push access to the repository can complete the merge.

About pull request merges

In a pull request, you propose that changes you've made on a head branch should be merged into a base branch. By default, any pull request can be merged at any time, unless the head branch is in conflict with the base branch. However, there may be restrictions on when you can merge a pull request into a specific branch. For example, you may only be able to merge a pull request into the default branch if required status checks are passing. For more information, see "About protected branches."

您可以配置拉取请求在满足所有合并要求时自动合并。 有关详细信息,请参阅“自动合并拉取请求”。

If the pull request has merge conflicts, or if you'd like to test the changes before merging, you can check out the pull request locally and merge it using the command line.

You can't merge a draft pull request. For more information about draft pull requests, see "About pull requests."

The repository may be configured so that the head branch for a pull request is automatically deleted when you merge a pull request. For more information, see "Managing the automatic deletion of branches."

Note: 如果您在拉取请求合并后删除头部分支,GitHub 会检查将已删除分支指定为基础分支的同一仓库中的任何开放拉取请求。 GitHub 将自动更新任何此类拉取请求,将其基础分支更改为合并的拉取请求的基础分支。 For more information, see "About branches."

Pull requests are merged using the --no-ff option, except for pull requests with squashed or rebased commits, which are merged using the fast-forward option.

你可以将拉取请求链接到问题,以显示修复正在进行中,并在某人合并拉取请求时自动关闭该问题。 有关详细信息,请参阅“将拉取请求链接到问题”。

If you decide you don't want the changes in a topic branch to be merged to the upstream branch, you can close the pull request without merging.

Merging a pull request

  1. 在存储库名称下,单击 “拉取请求”。 问题和拉取请求选项卡选择

  2. In the "Pull Requests" list, click the pull request you'd like to merge.

  3. Depending on the merge options enabled for your repository, you can:

    Note: Rebase and merge will always update the committer information and create new commit SHAs. For more information, see "About pull request merges."

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

    有关 squash 合并的默认提交消息的信息,请参阅“关于拉取请求合并”。 Commit message field

  5. If you have more than one email address associated with your account on, 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 <username> is the default commit author email address. For more information, see "Setting your commit email address." Choose commit email addresses

    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.

若要详细了解 GitHub CLI,请参阅“关于 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. For more information about the merge methods that you can choose, see "About pull request merges."

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

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

Further reading