Sub topic 10
Pull requests, squash merges, and PR titles
This chapter assumes you can write a conventional commit, know the type list (feat, fix, and so on), and understand how ! and BREAKING CHANGE map to Semantic Versioning. It covers how the convention behaves when your team merges through pull requests.
Why the merge strategy matters
Conventional Commits only helps if the commits on your main branch follow the format. Which commits land there depends on how you merge a pull request (PR).
| Merge strategy | What lands on main | Convention applies to |
|---|---|---|
| Merge commit | Every branch commit, plus a merge commit | Each branch commit and the merge message |
| Rebase and merge | Every branch commit, replayed linearly | Each branch commit |
| Squash and merge | One new commit for the whole PR | The squash commit message only |
With merge commits or rebasing, every commit on the branch must be well formed. Messages like wip or fix typo end up in the permanent history. With squash merges, the branch can be messy, because only one message survives.
Squash merges and the PR title
Many hosting platforms build the squash commit's first line from the PR title. Some use the branch's single commit message when the PR has only one commit, and settings differ per platform and repository. Check what yours does.
If your platform uses the PR title as the commit subject, the PR title is the conventional commit header. Write it in the same format:
feat(parser): add support for array literalsThe PR description often becomes the commit body. You can put a BREAKING CHANGE: footer or a Refs: #482 footer there, as long as it ends up in the final squash message.
Because the diagram fence must name its type, here is the flow as a diagram:
Checking the PR title in CI
Reviewers forget to check titles, so automate it. The title is available in the CI event data, and you can lint it with the same commitlint config you use locally. This GitHub Actions workflow does that:
name: Lint PR title
on:
pull_request:
types: [opened, edited, synchronize, reopened]
jobs:
commitlint:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm install --no-save @commitlint/cli @commitlint/config-conventional
- env:
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
echo "module.exports = { extends: ['@commitlint/config-conventional'] };" > commitlint.config.js
echo "$PR_TITLE" | npx commitlintThe title goes through an environment variable instead of being pasted into the shell command. A title is untrusted input, and interpolating it directly into run: would allow command injection. The edited trigger re-runs the check when someone fixes the title.
Common problems
- The title is right but the commit is not. Some platforms default to the title plus a list of all branch commit messages as the body. That body can contain stray
BREAKING CHANGEtext or noise. Set the default to "pull request title and description" if available, or edit the message at merge time. - One PR, several changes. A squash merge produces one type. If a PR adds a feature and fixes an unrelated bug, the changelog shows only one of them. Split the PR, or use rebase merging with clean commits.
- Wrong type after review. If review changes the nature of the work, update the title. The check re-runs, and the final commit reflects the real change.
- Breaking change missing from the squash. A
!on a branch commit is lost if the title lacks it. Put the!in the PR title as well.
Choosing a strategy
Squash merging suits teams that value a linear history with one commit per PR and do not want to police every branch commit. Rebase merging suits teams that write careful, atomic commits and want each one in the changelog. Whichever you choose, apply the convention to the thing that actually lands on main.
Exercise
Your team squash merges and the platform uses the PR title as the commit subject. A PR removes a public function and its title is "refactor(utils): drop legacy helper". What is wrong, and what should the title and description contain?
Show answer
The change breaks the public API, but the title hides that, so release tooling would not bump the MAJOR version. The title should mark the break, for example "refactor(utils)!: drop legacy helper", and the description should include a footer such as "BREAKING CHANGE: legacyHelper() was removed; use newHelper() instead." Check that the footer appears in the final squash commit message.
Exercise
Why does the CI workflow pass the PR title through an environment variable instead of writing it directly in the shell command?
Show answer
The title is untrusted text from the PR author. Inserting it directly into the script lets a crafted title run arbitrary shell commands. An environment variable is treated as data, not code.