<name>/<description>, or to carry an issue key such as SMC-75, so you can tell who owns a branch or link it to your tracker at a glance.
A branch that meets none of the accepted names fails the smartcloud / branches check, with a message that lists what the policy accepts.
Turn it on
1
Add a branches section with at least one accepted name
.github/smartcloud.yml
names has at least one entry.2
Exempt your bots
Bots name their own branches. Exempt them by branch or by author:
.github/smartcloud.yml
3
Run on pull request events
The feature runs on pull request events and only records findings. It needs
checks: write for its check run, and pull-requests: write so a failing branch name reaches the report comment smartcloud posts or updates on the pull request.4
Enforce it
To block merging, require
smartcloud / branches in the ruleset, or use the required aggregate, which counts it with the rest. Start with level: warning to report the policy without blocking while a team moves over.Options
Each entry in
names needs a preset, a pattern, or both. With both, the branch must meet both. prefixes only go with prefixed and keys only with issueKey; anything else is a config error.
Accepted names
prefixed:<prefix>/<description>: a non-empty prefix, a slash and a non-empty description, such asann/fix-typoorfeat/size-labels. Listprefixesto accept only those.issueKey: an issue key anywhere in the name, such assmc-75inann/smc-75-branch-names. A key is a letter, up to nine more letters or digits, a hyphen and a number, with no letter or digit either side, in any case. Listkeysto accept only your tracker’s: GitHub’s ownpatch-1has the same shape.pattern: a regular expression, such as^release/\d+\.\d+$.
Complete example
.github/smartcloud.yml
How it works
On every pull request event, the feature reads the head branch and the author.- If the author is in
exempt.authors, or the branch matches anexempt.branchespattern, nothing is checked. - If the branch meets any entry in
names, it passes. - Otherwise it records a finding (rule
branches.name) atlevel. The finding says the branch does not follow the policy, lists the accepted names (or showsmessageinstead), and asks for the work to be pushed to a correctly named branch.
What you will see on GitHub
-
A
smartcloud / branchescheck run: failure for a bad name atlevel: error, neutral atlevel: warning, success otherwise. -
The finding in the report comment on the pull request, for example:
- The same finding in the job summary and as an annotation on the run.
Forks and restricted runs
The feature only reads the pull request, so it works the same on forks and Dependabot pull requests. A fork’s read-only token may not be able to post the report comment or the check run; those writes are skipped and listed under Restricted access in the job summary (see Restricted runs), and the job’s own result still carries the finding. Dependabot’s branches start withdependabot/, so exempt them.
Troubleshooting
The feature does not run at all
The feature does not run at all
branches needs at least one entry under names. A section with only exempt or level is skipped as not
configured.patch-1 passes the issueKey preset
patch-1 passes the issueKey preset
GitHub’s web editor names branches like
patch-1, which has the shape of an issue key. List your tracker’s keys,
such as [SMC].Config warning: a branch name needs a preset or a pattern; prefixes go with the prefixed preset, keys with issueKey
Config warning: a branch name needs a preset or a pattern; prefixes go with the prefixed preset, keys with issueKey
Every entry in
names needs preset or pattern, prefixes needs preset: prefixed, and keys needs preset: issueKey.A bot's pull request fails the policy
A bot's pull request fails the policy
Add its branch prefix to
exempt.branches (^dependabot/, ^renovate/) or its exact login to exempt.authors
(renovate[bot]).How do I fix a pull request with a badly named branch?
How do I fix a pull request with a badly named branch?
Create a new branch with an accepted name from the same commit, push it, open a pull request from it, and close the
old one. GitHub cannot rename the head branch of an open pull request.