Sub topic 9
Choosing which merge methods a repository allows
This chapter assumes you can open and review a pull request, and that you know what the three merge methods do to the base branch. You should also be comfortable reading git log --graph output. Here you will decide which of those methods a repository offers and how to configure that. The next chapter covers enforcing a linear history.
Why restrict merge methods at all
By default, a new repository allows all three methods: merge commit, squash and merge, and rebase and merge. Every person with write access can pick any of them on every pull request. That is flexible, but it produces a base branch whose history mixes three shapes. Some pull requests appear as one commit, some as a merge commit with two parents, and some as a run of rewritten commits.
A mixed history is harder to read and harder to revert. Each shape needs a different revert command, and a bisect behaves differently across them. Restricting the allowed methods turns a team convention into something GitHub enforces. People can no longer pick the wrong button by habit.
Remember that these settings apply to the whole repository. They are not per branch. Rulesets can narrow the choice for specific branches, as described later.
Where the settings live
You need admin permission on the repository. Open Settings, then General, and scroll to the Pull Requests section. These options control merging:
| Setting | Effect |
|---|---|
| Allow merge commits | Offers "Create a merge commit" |
| Allow squash merging | Offers "Squash and merge" |
| Allow rebase merging | Offers "Rebase and merge" |
| Always suggest updating pull request branches | Shows an "Update branch" button when the head branch is behind the base |
| Allow auto-merge | Lets a pull request merge itself once required checks and reviews pass |
| Automatically delete head branches | Deletes the head branch after the pull request merges |
At least one of the three methods must stay enabled. GitHub does not let you turn all of them off, because the repository would have no way to merge a pull request.
Each enabled method adds an entry to the dropdown on the green merge button. If only one method is enabled, the dropdown disappears and the button performs that method. If several are enabled, GitHub remembers the method you used last and shows it as your default. That memory is per user, so it does not make the team consistent.
Default commit messages
When you enable squash merging or merge commits, GitHub lets you choose how it pre-fills the commit message. These defaults matter because most people accept whatever the dialog shows.
For squash merging, you can choose the default title and body:
- Pull request title, which is the default and gives a clean one-line subject.
- Pull request title and commit details, which lists every commit message in the body.
- Pull request title and description, which uses the pull request body as the commit body.
- Default message, which uses the single commit's message if the branch has one commit and the pull request title otherwise.
For merge commits, the choices are the default message (Merge pull request #123 from owner/branch), the pull request title, or the pull request title and description.
The squash default of "Default message" has a known quirk. A pull request with one commit gets that commit's message, and a pull request with two gets the pull request title. The same repository can then produce subjects of two different styles. Setting the title to "Pull request title" removes that inconsistency. It also makes the squash subject match the pull request title, which includes the (#123) suffix GitHub appends.
Pulling in the pull request description can leak noise into history. A template with checkboxes and "Closes #45" lines will end up in the commit body. Decide whether you want that before you select it.
Configuring from the command line
The web page is not the only way. A script is easier to review and repeat across many repositories. gh repo edit covers the main toggles:
gh repo edit OWNER/REPO \
--enable-merge-commit=false \
--enable-squash-merge=true \
--enable-rebase-merge=false \
--delete-branch-on-merge=trueThis leaves squash and merge as the only method and deletes branches after merging. To check the current state, ask for the matching JSON fields:
gh repo view OWNER/REPO --json mergeCommitAllowed,squashMergeAllowed,rebaseMergeAllowedThe commit message defaults are not exposed as gh repo edit flags. Use the REST API through gh api. The title and message fields must be sent together. The -F flag sends typed values such as booleans, and -f sends strings.
gh api -X PATCH repos/OWNER/REPO \
-F allow_squash_merge=true \
-F allow_merge_commit=false \
-F allow_rebase_merge=false \
-f squash_merge_commit_title=PR_TITLE \
-f squash_merge_commit_message=PR_BODYPR_TITLE uses the pull request title as the subject. PR_BODY uses the pull request description as the body. Other accepted values are COMMIT_OR_PR_TITLE for the title, and COMMIT_MESSAGES or BLANK for the message. For merge commits, the matching fields are merge_commit_title (PR_TITLE or MERGE_MESSAGE) and merge_commit_message (PR_BODY, PR_TITLE, or BLANK).
A request that disables all three methods is rejected by the API, as it is on the web.
How the settings interact with other rules
The merge method settings are one layer. Other features can narrow your choices further, so a method that is enabled may still be unavailable on a given branch.
- Require linear history. This branch protection rule blocks merge commits on the protected branch. If merge commits are enabled in settings but the rule is on, the "Create a merge commit" option cannot be completed there. Disable the unused method in settings too, so the dropdown does not offer an option that fails.
- Rulesets. The "Require a pull request before merging" rule in a ruleset has an Allowed merge methods option. It limits methods for the branches the ruleset targets. That is the way to allow squash on
mainbut also allow merge commits on a long-livedreleasebranch, for example. - Merge queue. If you use a merge queue, the queue has its own merge method setting, and it governs how queued pull requests land.
- Auto-merge. When a user enables auto-merge, they choose a method at that point. Only enabled methods are listed.
When two settings disagree, the stricter one wins. Check the dropdown on a real pull request after changing settings, because that shows what is actually available.
Deciding what to enable
There is no universal answer, and the next chapters cover the trade-offs between methods. These are common configurations and the reasoning behind each:
| Configuration | Typical fit | Main cost |
|---|---|---|
| Squash only | Small pull requests, one logical change each, messy work-in-progress commits | Loses individual commit history, and follow-up branches need `rebase --onto` |
| Rebase only | Teams that write clean, atomic commits and want a straight line | Rewrites commit SHAs, and cannot resolve conflicts on the web |
| Merge commit only | Teams that want exact history and easy revert of a whole pull request | Graph has many merge nodes |
| Squash plus merge commit | Squash for features, merge commit for release or sync branches | Two shapes in history, and needs a ruleset to keep them apart |
| All three | Open source projects where maintainers decide per pull request | Inconsistent history |
Two guidelines help when you are unsure. First, enable the fewest methods that cover your real workflows. You can always enable another later, but removing one after people depend on it causes friction. Second, pick the default message settings at the same time you pick the methods. A squash-only repository with the "Default message" title setting still produces uneven subjects.
Common mistakes
- Disabling the method a bot uses. Dependency update tools and auto-merge workflows request a specific method, such as
squash. If you disable it, their merges fail with an error about the method not being allowed. Check configured bots before restricting methods. - Forgetting forks and other repositories. Settings are per repository. A fork has its own settings, and a template repository does not copy these options into repositories created from it.
- Assuming write access is enough. Only admins change these settings. Maintainers who can merge cannot change the available methods, so they may not understand why a button is missing.
- Expecting existing history to change. The settings affect future merges. Pull requests already merged keep the shape they were merged with.
Exercise
A team enables only "Allow squash merging" and "Allow rebase merging". A developer sets the squash message default to "Default message". Two pull requests are squash-merged: one has a single commit, the other has four commits. What differs between their commit subjects, and which setting fixes it?
Show answer
The single-commit pull request gets that commit's message as the subject, and the four-commit pull request gets the pull request title. Changing the squash default to "Pull request title" (API value PR_TITLE) makes every squash commit use the pull request title as its subject.
Exercise
You run gh api -X PATCH repos/OWNER/REPO -F allow_squash_merge=false -F allow_merge_commit=false -F allow_rebase_merge=false. What happens, and why?
Show answer
The request is rejected. A repository must keep at least one merge method enabled, because otherwise no pull request could be merged.