Pull requests can be merged in different ways. The best strategy depends on how your team wants the repository history to look and how much detail you want to preserve from the pull request branch.
| Strategy | Result | Choose when |
|---|---|---|
| Merge commit | Preserves every commit from the pull request branch and adds an explicit merge point. | Your team values complete history, or the individual commits are meaningful on their own. |
| Squash and merge | Combines all commits in the pull request into a single commit on the base branch. | A pull request represents one logical change, especially with many small fixup commits. |
| Rebase and merge | Adds each commit onto the base branch without a merge commit, for a linear history. | Your team wants a linear history and the commits are already organized clearly. |
Merge your commits
Quando você clica na opção padrão Mesclar solicitação de pull em uma solicitação de pull, todos os commits da ramificação de recursos são adicionados à ramificação base em um commit de mesclagem. A solicitação de pull é mesclada por meio da opção --no-ff.
Para mesclar as solicitações de pull, você precisa ter permissões de gravação no repositório.

A merge commit preserves the full commit history from the pull request branch. This makes it easier to see every commit that led to the final change, including review fixes and intermediate work. It also creates an explicit merge point in the base branch history.
Choose this strategy when your team values complete history or when the individual commits in a pull request are meaningful on their own.
Squash and merge your commits
Quando você seleciona a opção Combinar por squash e mesclar em uma solicitação de pull, os commits da solicitação de pull são combinados por squash em um só commit. Em vez de ver todos os commits individuais de um contribuidor de um branch de tópico, os commits são combinados em um commit e mesclados no branch-padrão. As solicitações de pull com commits mesclados por squash são mescladas com a opção de avanço rápido.
Para mesclar por squash e mesclar solicitações de pull, você precisa ter permissões de gravação no repositório, e o repositório precisa permitir a mesclagem squash.

Você pode usar combinação por squash e merge para criar um histórico de Git mais simplificado no seu repositório. Os commits de trabalho em andamento são úteis ao trabalhar em um branch de recurso, mas não são necessariamente importantes para manter no histórico do Git. Se você combinar esses commits por squash em um só commit ao mesclá-los com o branch padrão, as alterações serão consolidadas, resultando em um histórico limpo do Git.
Squashing turns all commits in the pull request into one commit on the base branch. This keeps the default branch history concise and can make it easier to scan later. The tradeoff is that intermediate commits from the pull request are not preserved as separate commits on the base branch.
Choose this strategy when a pull request represents one logical change, especially if the branch includes many small fixup commits.
Merge message for a squash merge
When you squash and merge, GitHub generates a default commit message that you can edit. The default message can include the pull request title, pull request description, or commit information, depending on repository settings and the number of commits in the pull request.
Maintainers and administrators can configure the default message for squashed commits. See Configurar a combinação de confirmações por squash em solicitações de pull.
Squashing and merging a long-running branch
Squash merging works best for short-lived branches. If you keep working on the same head branch after a squash merge, later pull requests can include commits that were already squashed into the base branch. This can make merge conflicts more likely and can force you to resolve the same conflicts more than once.
For long-running branches, consider using a merge commit or rebasing the branch before opening the next pull request.
Rebase and merge your commits
Quando você seleciona a opção Troca de base e mesclagem em uma solicitação de pull, todos os commits da ramificação do tópico (ou da ramificação principal) são adicionados à ramificação base individualmente, sem um commit de mesclagem. Dessa forma, o comportamento de rebase e mesclagem se assemelha a uma mesclagem fast-forward, mantendo um histórico linear do projeto. No entanto, o rebase faz isso reescrevendo o histórico de commits no ramo base por meio de novos commits.
O comportamento de rebase e mesclagem em GitHub desvia ligeiramente de git rebase fora de GitHub. Basear novamente e mesclar em GitHub:
- Sempre atualiza as informações do responsável pelo commit e cria novos SHAs de commit, enquanto
git rebasenão altera as informações do responsável pelo commit quando o rebase é feito sobre um commit ancestral. - Descarta confirmações que estavam vazias para começar, como aquelas criadas com
git commit --allow-empty, enquantogit rebasemantém confirmações originalmente vazias por padrão.
Para obter mais informações sobre git rebase, confira git-rebase na documentação do Git.
Para troca de base e mesclagem das solicitações de pull, você precisa ter permissões de gravação no repositório e o repositório precisa permitir a troca de base e a mesclagem.
Para ver uma representação visual de git rebase, confira o capítulo "Ramificação do Git – Troca de base " do livro Pro Git.
Rebasing adds each commit from the pull request branch onto the base branch without creating a merge commit. This produces a linear history while preserving the individual commits from the pull request.
Choose this strategy when your team wants a linear history and the pull request commits are already organized clearly. If GitHub cannot safely rebase the pull request automatically, you can rebase locally, resolve conflicts, and push the updated branch. See Resolving a merge conflict using the command line and Merging a pull request.
Indirect merges
A pull request can be marked as merged if its head branch commits become reachable from the base branch outside that pull request. This can happen when the same commits are merged through another pull request or pushed directly to the default branch.
Indirect merges are uncommon, but they can affect automation and branch protection expectations. Pull requests merged indirectly are marked as merged even if branch protection rules on that pull request were not satisfied.