Sub topic 10
Pull requests, squash merges, and PR titles
This chapter assumes you can open and merge a pull request (PR) on a hosting service such as GitHub or GitLab. It also assumes you know the Conventional Commits structure from earlier chapters: type, optional scope, description, body, and footers. The examples use GitHub. Other hosts have similar settings under different names.
Why the merge strategy decides which messages matter
Release tools and changelog generators read the commits that land on your main branch. They do not read the commits on a feature branch before it merges. Which messages count as "history" therefore depends on how your team merges.
A feature branch often holds messages like these:
wip
fix typo
address review comments
try againIf all four reach main, the history is noisy and no tool can derive a version bump from it. A team has two ways to deal with this:
- Require every commit on every branch to follow the convention.
- Let branch commits be informal, and make the single commit that lands on
mainconventional.
The second option is usually easier to adopt. It relies on squash merges and a conventional PR title.
The three merge strategies
Git hosts typically offer three ways to merge a PR. They differ in what ends up on the main branch.
| Strategy | What lands on `main` | Where the conventional message comes from |
|---|---|---|
| Merge commit | All branch commits plus one extra merge commit | Every branch commit, plus the auto-generated merge message |
| Squash merge | One new commit containing the whole diff | The PR title and, optionally, the PR description or commit details |
| Rebase merge | Each branch commit, replayed on top of `main` | Every branch commit |
With a merge commit, the generated message looks like Merge pull request #42 from user/branch. It is not conventional, and it never will be unless you edit it by hand each time. Most linters skip merge commits by default. Release tools that parse history usually ignore them too, but they still read the branch commits underneath. Those must all be conventional.
With a rebase merge, the same applies without the merge commit. Each commit on the branch is individually visible on main.
With a squash merge, the whole branch collapses into one commit. You control that one message. This is why teams adopting Conventional Commits often standardize on squash merges.
The PR title becomes the commit subject
When you squash merge on GitHub, the repository settings decide the default commit message. The wording of the options can change, but they generally include:
- Default message: the single commit's message if the PR has one commit, otherwise the PR title.
- Pull request title: always the PR title as the subject.
- Pull request title and commit details: the title as subject, and a list of the branch commit messages as the body.
- Pull request title and description: the title as subject, and the PR description as the body.
For a Conventional Commits workflow, set the default to the PR title. The first option has a trap. A PR with one commit uses that commit's message, so a PR containing only fix typo would land as fix typo. A PR with two commits would use the PR title. The result depends on commit count, which nobody remembers to check.
GitHub appends the PR number to the subject, so the landed commit reads feat(search): add fuzzy matching (#42). That is still valid, because the description is free text. The number links the commit back to its PR discussion.
Check the final message before you click merge
The merge dialog lets you edit the subject and body before you confirm. Treat it as the last quality gate:
- Confirm the subject is conventional and its type is correct for the whole PR, not only for the last commit.
- Check the body. With "commit details", the body is a bulleted list of branch commit messages such as
* wipand* fix typo. Delete that noise or replace it with a real summary. - Check that any
BREAKING CHANGE:orRefs:footers are present and sit at the end of the message, after a blank line.
One PR, one type
A squash merge produces one commit, and that commit has one type. This has a practical consequence for PR scope.
Suppose a branch adds a feature and also fixes an unrelated bug it ran into. Both changes cannot be represented in one subject. Two honest options exist:
- Split the PR into two PRs, one
featand onefix. The history and the changelog then show both changes. - Keep one PR and pick the type of the most significant change. The bug fix is then invisible to the changelog.
Splitting is the better habit. Small PRs are also easier to review. When a PR genuinely contains several changes that cannot be split, use a rebase merge and keep one conventional commit per change. That requires every branch commit to be conventional and clean.
Breaking changes in squashed commits
A squash merge keeps the markers that tell release tools about a breaking change, but only if you put them in the final message. A ! in the PR title is enough:
feat(api)!: remove the deprecated /v1/users endpoint (#57)If you also want the explanatory footer, it has to be in the commit body. When the PR description becomes the body, write the footer in the description so it lands correctly:
Removes the /v1/users routes and their handlers.
BREAKING CHANGE: clients must call /v2/users instead.A common failure is a BREAKING CHANGE: footer written in one of the branch commits while the PR title has no !. With "title only" or "title and description" squash settings, that branch commit message is discarded, and the release tool sees an ordinary feat. The next release is then a MINOR bump instead of a MAJOR one. With "title and commit details", the footer lands in the middle of a bulleted list rather than in a separate footer block, and some parsers will miss it. Putting ! in the PR title avoids both problems.
Validating PR titles in CI
If the PR title is the real commit message, validate it. You can do this with a short workflow that needs no third-party action. The pattern is the same one used in the commit-msg hook from the enforcement chapter.
name: pr-title
on:
pull_request:
types: [opened, edited, synchronize, reopened]
jobs:
check-title:
runs-on: ubuntu-latest
steps:
- name: Check PR title follows Conventional Commits
env:
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
pattern='^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\([a-z0-9._-]+\))?!?: .+'
if ! printf '%s\n' "$PR_TITLE" | grep -Eq "$pattern"; then
echo "PR title must look like: type(scope)!: description" >&2
echo "Got: $PR_TITLE" >&2
exit 1
fiTwo details matter here.
- The
editedevent type is required. Without it, the check runs when the PR opens and not when someone fixes the title. The check then stays red until a new push. - The title is passed through an environment variable, not pasted into the script with
${{ ... }}. PR titles are untrusted input. Interpolating them directly into a shell script allows command injection by anyone who can open a PR.
If you already use commitlint, you can reuse its ruleset instead of a hand-written pattern. Install the packages as in the enforcement chapter, then run this in the workflow after the install step:
printf '%s\n' "$PR_TITLE" | npx commitlintThen your local hook, your CI commit check, and your PR title check all enforce the same rules. Make the check a required status in the branch protection settings. Otherwise it is advisory and people will merge past it.
Keeping the branch commits useful too
You do not have to forbid informal branch commits, but local hooks still catch problems early. A commit-msg hook that rejects wip annoys people who commit often. Many teams therefore enforce the convention only on the PR title and leave branch commits alone. Pick one policy and write it in your contributing guide. A mixed policy confuses contributors.
If you use squash merges and also want branch commits to be conventional, there is no technical conflict. The branch commits are simply discarded or listed in the body.
Edge cases
- Dependency bots. Tools such as Dependabot and Renovate can be configured to open PRs with conventional titles, for example
chore(deps): bump lodash from 4.17.20 to 4.17.21. Configure their commit message prefix once. Otherwise every bot PR fails your title check. - Reverts. The GitHub revert button creates a PR titled
Revert "feat: add search". That does not match therevert:type pattern. Rename the title torevert: add searchbefore merging. - Direct pushes. Squash merges only control what happens through PRs. If anyone can push directly to
main, those commits bypass the title check. Protect the branch so that merging happens only through PRs. - Long-lived branches. A release branch merged back into
mainwith a squash merge collapses many changes into one commit, and the changelog loses detail. Use a merge commit or rebase merge for that case.
Summary of a workable setup
- Set the repository's squash merge default to the PR title.
- Disable merge commits and rebase merges, unless you have a specific need for them.
- Add a required CI check that validates the PR title.
- Protect
mainso that every change goes through a PR. - Review the squash message in the merge dialog, especially the body.
Exercise
A PR contains a single commit with the message "wip". The PR title is "feat(search): add fuzzy matching". The repository's squash merge default is "Default message". What subject lands on main, and which setting would make the result predictable?
Show answer
Because the PR has a single commit, "Default message" uses that commit's message, so the subject is "wip" (plus the PR number). Setting the squash default to "Pull request title" makes the PR title the subject regardless of how many commits the PR has.
Exercise
A developer writes "BREAKING CHANGE: drop Node 16" as a footer in one branch commit. The PR title is "feat(cli): add --json flag" and the repository uses "Pull request title" for squash merges. What version bump will a release tool produce, and how should the PR be fixed?
Show answer
The footer is discarded in the squash, so the tool sees an ordinary feat and produces a MINOR bump. Fix it by changing the title to "feat(cli)!: add --json flag" or by adding the BREAKING CHANGE footer to the final squash message, so the tool produces a MAJOR bump.