Skip to content

Commit 4ddbaf7

Browse files
AbhishekBhaskarlecoursenjc-clark
authored
Add documentation for configurable branch name options for pull-request-branch-name (#62394)
Co-authored-by: Laura Coursen <lecoursen@github.com> Co-authored-by: Joe Clark <31087804+jc-clark@users.noreply.github.com>
1 parent 0cdacc2 commit 4ddbaf7

4 files changed

Lines changed: 235 additions & 9 deletions

File tree

content/code-security/how-tos/secure-your-supply-chain/manage-your-dependency-security/customizing-dependabot-security-prs.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ To **track progress** towards a project goal or release, use `milestone` to asso
7676

7777
For detailed guidance, see [Associating pull requests with a milestone](/code-security/tutorials/secure-your-dependencies/customizing-dependabot-prs#associating-pull-requests-with-a-milestone).
7878

79-
## Changing the separator in the pull request branch name
79+
## Customizing pull request branch names
8080

81-
To ensure your **branch names align** with your team's existing conventions, use `pull-request-branch-name.separator` to specify the separator you want {% data variables.product.prodname_dependabot %} to use for branch names.
81+
To ensure your **branch names align** with your team's existing conventions, use `pull-request-branch-name` to customize how {% data variables.product.prodname_dependabot %} generates branch names—including the separator, prefix, length, casing, and format.
8282

83-
For detailed guidance, see [Changing the separator in the pull request branch name](/code-security/tutorials/secure-your-dependencies/customizing-dependabot-prs#changing-the-separator-in-the-pull-request-branch-name).
83+
For detailed guidance, see [Customizing pull request branch names](/code-security/tutorials/secure-your-dependencies/customizing-dependabot-prs#customizing-pull-request-branch-names).
8484

8585
## Example 1: configuration for security updates only
8686

content/code-security/reference/supply-chain-security/dependabot-options-reference.md

Lines changed: 103 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,106 @@ Package manager | YAML value | Supported versions |
621621
| {% endif %} |
622622
| yarn | `npm` | v1, v2, v3, v4 |
623623

624-
## `pull-request-branch-name.separator` {% octicon "versions" aria-label="Version updates" height="24" %} {% octicon "shield-check" aria-label="Security updates" height="24" %}
624+
## `pull-request-branch-name` {% octicon "versions" aria-label="Version updates" height="24" %} {% octicon "shield-check" aria-label="Security updates" height="24" %}
625+
626+
{% ifversion dependabot-branch-name-options %}
627+
628+
Configure how {% data variables.product.prodname_dependabot %} generates branch names for pull requests. You can customize the separator, prefix, length, casing, word separator, and provide a custom template. For examples, see [AUTOTITLE](/code-security/tutorials/secure-your-dependencies/customizing-dependabot-prs).
629+
630+
{% data variables.product.prodname_dependabot %} default behavior:
631+
632+
* Generate branch names of the form: `dependabot/PACKAGE-MANAGER/DEPENDENCY`
633+
634+
| Parameter | Type | Default | Description |
635+
|-----------|------|---------|-------------|
636+
| [`separator`](#separator) | String | `"/"` | Character used between segments of the branch name. |
637+
| [`prefix`](#prefix) | String (max 50 characters) | `"dependabot"` | String prepended to the branch name. |
638+
| [`max-length`](#max-length) | Integer (20–244) | `100` | Maximum character length of the branch name. |
639+
| [`word-separator`](#word-separator) | String | Not set | Character to replace underscores (`_`) in branch name content after the prefix. |
640+
| [`branch-name-case`](#branch-name-case) | String | Not set | Apply case transformation to the branch name content after the prefix. |
641+
| [`template`](#template) | String (max 200 characters) | Not set | Custom format template using placeholders. |
642+
643+
All options are composable. When `template` is set alongside simple options, the processing order is:
644+
645+
1. Template rendering (placeholder substitution)
646+
1. Separator replacement (`/` replaced with configured separator)
647+
1. Word-separator replacement (`_` replaced with configured word-separator)
648+
1. Case transformation applied to content after the prefix
649+
1. Max-length truncation
650+
651+
### `separator`
652+
653+
Specify a character to use in place of `/` between branch name segments.
654+
655+
Supported values: `"-"`, `_`, `/`
656+
657+
For example, with `separator: "-"`: `dependabot/npm_and_yarn/lodash-4.17.21` becomes `dependabot-npm_and_yarn-lodash-4.17.21`.
658+
659+
> [!TIP]
660+
> The hyphen symbol must be escaped so it is not interpreted as starting an empty YAML list.
661+
662+
### `prefix`
663+
664+
Specify a custom string to use at the start of the branch name instead of the default `dependabot`.
665+
666+
The value can be up to 50 characters.
667+
668+
For example, with `prefix: "deps"`: `dependabot/npm_and_yarn/lodash-4.17.21` becomes `deps/npm_and_yarn/lodash-4.17.21`.
669+
670+
### `max-length`
671+
672+
Set the maximum allowed length for generated branch names.
673+
674+
* Minimum value: `20`.
675+
* Maximum value: `244`.
676+
* Default value: `100`.
677+
* When a branch name exceeds this limit, it is truncated and a hash suffix is appended to preserve uniqueness.
678+
679+
For example, with `max-length: 40`, a branch name like `dependabot/npm_and_yarn/some-long-dependency-name-1.0.0` is truncated to 40 characters with a hash suffix.
680+
681+
### `word-separator`
682+
683+
Specify a character to replace underscores (`_`) in all branch name content after the prefix—including package manager names, dependency names, group names, and directory paths.
684+
685+
For example, with `word-separator: "-"`:
686+
687+
* `npm_and_yarn` → `npm-and-yarn`
688+
* `front_end_dir` → `front-end-dir`
689+
690+
### `branch-name-case`
691+
692+
Apply a case transformation to the branch name content after the prefix.
693+
694+
Supported values: `"lowercase"`, `"uppercase"`
695+
696+
For example, with `branch-name-case: "lowercase"`: `dependabot/npm_and_yarn/Lodash-4.17.21` becomes `dependabot/npm_and_yarn/lodash-4.17.21`.
697+
698+
### `template`
699+
700+
Define a custom branch name format using placeholders. The template gives you full control over the structure of generated branch names. For examples, see [AUTOTITLE](/code-security/tutorials/secure-your-dependencies/customizing-dependabot-prs).
701+
702+
Available placeholders depend on the update strategy:
703+
704+
| Placeholder | Solo updates | Grouped updates | Multi-ecosystem groups | Description |
705+
|-------------|:---:|:---:|:---:|-------------|
706+
| `{prefix}` | {% octicon "check" aria-label="Available" %} | {% octicon "check" aria-label="Available" %} | {% octicon "check" aria-label="Available" %} | The configured prefix (default `dependabot`). |
707+
| `{package_manager}` | {% octicon "check" aria-label="Available" %} | {% octicon "check" aria-label="Available" %} | {% octicon "x" aria-label="Not available" %} | The package ecosystem identifier (for example, `npm_and_yarn`). |
708+
| `{directory}` | {% octicon "check" aria-label="Available" %} | {% octicon "check" aria-label="Available" %} | {% octicon "x" aria-label="Not available" %} | The dependency file directory. |
709+
| `{target_branch}` | {% octicon "check" aria-label="Available" %} | {% octicon "check" aria-label="Available" %} | {% octicon "check" aria-label="Available" %} | The target branch if configured. |
710+
| `{dependency}` | {% octicon "check" aria-label="Available" %} | {% octicon "x" aria-label="Not available" %} | {% octicon "x" aria-label="Not available" %} | The dependency name(s). |
711+
| `{version}` | {% octicon "check" aria-label="Available" %} | {% octicon "x" aria-label="Not available" %} | {% octicon "x" aria-label="Not available" %} | The new version or ref. |
712+
| `{group_name}` | {% octicon "x" aria-label="Not available" %} | {% octicon "check" aria-label="Available" %} | {% octicon "check" aria-label="Available" %} | The configured group name. |
713+
| `{name}` | {% octicon "check" aria-label="Available" %} | {% octicon "check" aria-label="Available" %} | {% octicon "check" aria-label="Available" %} | Strategy-appropriate name: dependency and version for solo updates, group name for grouped updates. |
714+
715+
Template validation rules:
716+
717+
* All placeholders must be recognized and allowed for the update strategy in use.
718+
* Braces must be well-formed (no unclosed `{` or `}`).
719+
* Using `{package_manager}` in a multi-ecosystem group template raises a validation error because no single package manager applies.
720+
* The rendered branch name must be a valid Git reference name. Characters such as spaces, `~`, `^`, `:`, `?`, `*`, `[`, and `\` are not allowed, and sequences like `..` or `@{` are rejected.
721+
* For grouped and multi-ecosystem updates, a 10-character digest is automatically appended to the branch name to guarantee uniqueness. This is not user-controlled.
722+
723+
{% else %}
625724

626725
Specify a separator to use when generating branch names. For examples, see [AUTOTITLE](/code-security/tutorials/secure-your-dependencies/customizing-dependabot-prs).
627726

@@ -633,11 +732,13 @@ When `pull-request-branch-name.separator` is defined:
633732

634733
* Use the specified character in place of `/`.
635734

636-
Supported values: `"-"`, `_`, `/`
735+
Supported values: `"-"`, `_`, `/`
637736

638737
> [!TIP]
639738
> The hyphen symbol must be escaped so it is not interpreted as starting an empty YAML list.
640739

740+
{% endif %}
741+
641742
## `rebase-strategy` {% octicon "versions" aria-label="Version updates" height="24" %} {% octicon "shield-check" aria-label="Security updates" height="24" %}
642743

643744
Disable automatic rebasing of pull requests raised by {% data variables.product.prodname_dependabot %}.

content/code-security/tutorials/secure-your-dependencies/customizing-dependabot-prs.md

Lines changed: 123 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,131 @@ updates:
212212

213213
See also [`milestone`](/code-security/reference/supply-chain-security/dependabot-options-reference#milestone--) and [AUTOTITLE](/issues/using-labels-and-milestones-to-track-work/about-milestones).
214214

215-
## Changing the separator in the pull request branch name
215+
## Customizing pull request branch names
216216

217217
{% data variables.product.prodname_dependabot %} generates a branch for each pull request. Each branch name includes `dependabot`, as well as the name of the package manager and the dependency to be updated. By default, these parts of the branch name are separated by a `/` symbol, for example:
218218
* `dependabot/npm_and_yarn/next_js/acorn-6.4.1`
219219

220+
{% ifversion dependabot-branch-name-options %}
221+
222+
You can customize branch names using the `pull-request-branch-name` option with the following parameters: `separator`, `prefix`, `max-length`, `word-separator`, `branch-name-case`, and `template`. All options are composable, and you can combine any of them. For the full reference of each parameter, see [`pull-request-branch-name`](/code-security/reference/supply-chain-security/dependabot-options-reference#pull-request-branch-name--).
223+
224+
### Combining formatting options
225+
226+
You can combine `separator`, `word-separator`, `branch-name-case`, `max-length`, and `template` to produce branch names that meet your system's requirements. For example, Docker tag compatibility, Azure Container Registry naming, or Kubernetes branch length limits.
227+
228+
When `template` is set alongside other options, formatting is applied as post-processing after template rendering in this order: separator replacement, word-separator replacement, case transformation, then max-length truncation.
229+
230+
```yaml copy
231+
# Combine template with formatting options
232+
233+
version: 2
234+
updates:
235+
- package-ecosystem: "npm"
236+
directory: "/"
237+
schedule:
238+
interval: "weekly"
239+
pull-request-branch-name:
240+
template: "{prefix}/{package_manager}/{dependency}-{version}"
241+
separator: "-"
242+
word-separator: "-"
243+
branch-name-case: "lowercase"
244+
max-length: 80
245+
```
246+
247+
* **Before** (default): `dependabot/npm_and_yarn/Lodash-4.17.21`
248+
* **After** (with above config): `dependabot-npm-and-yarn-lodash-4.17.21`
249+
250+
When a branch name exceeds `max-length`, it is truncated with a hash suffix to preserve uniqueness.
251+
252+
### Full example with multi-ecosystem groups
253+
254+
The following `dependabot.yml` demonstrates all available options across different ecosystems, including multi-ecosystem group configuration:
255+
256+
```yaml copy
257+
# Full example demonstrating all branch name options
258+
259+
version: 2
260+
261+
multi-ecosystem-groups:
262+
infrastructure:
263+
schedule:
264+
interval: "weekly"
265+
pull-request-branch-name:
266+
template: "{prefix}/infra/{name}"
267+
word-separator: "-"
268+
branch-name-case: "lowercase"
269+
270+
updates:
271+
- package-ecosystem: "npm"
272+
directory: "/"
273+
schedule:
274+
interval: "weekly"
275+
pull-request-branch-name:
276+
separator: "-"
277+
word-separator: "-"
278+
branch-name-case: "lowercase"
279+
groups:
280+
frontend-deps:
281+
patterns: ["react*", "next*"]
282+
283+
- package-ecosystem: "docker"
284+
directory: "/"
285+
schedule:
286+
interval: "monthly"
287+
pull-request-branch-name:
288+
template: "{prefix}/{package_manager}/{dependency}-{version}"
289+
max-length: 60
290+
291+
- package-ecosystem: "pip"
292+
directory: "/backend"
293+
schedule:
294+
interval: "weekly"
295+
pull-request-branch-name:
296+
prefix: "deps"
297+
branch-name-case: "lowercase"
298+
groups:
299+
django-deps:
300+
patterns: ["django*"]
301+
302+
# These entries participate in the "infrastructure" multi-ecosystem group
303+
- package-ecosystem: "docker"
304+
directory: "/infra"
305+
patterns: ["nginx", "redis", "postgres"]
306+
multi-ecosystem-group: "infrastructure"
307+
308+
- package-ecosystem: "terraform"
309+
directory: "/infra"
310+
patterns: ["hashicorp/*"]
311+
multi-ecosystem-group: "infrastructure"
312+
```
313+
314+
This configuration produces the following branch names:
315+
316+
| Scenario | Strategy | Branch name |
317+
|----------|----------|-------------|
318+
| lodash npm update | Solo | `dependabot-npm-and-yarn-lodash-4.17.21` |
319+
| npm frontend-deps group update | Grouped | `dependabot-npm-and-yarn-frontend-deps-fc93691fd4` |
320+
| nginx solo Docker update | Solo | `dependabot/docker/nginx-1.25.0` |
321+
| pip Django update | Solo | `deps/pip/django-4.2.1` |
322+
| pip django-deps group update | Grouped | `deps/pip/django-deps-a1b2c3d4e5` |
323+
| Cross-ecosystem infrastructure group (Docker + Terraform) | Multi-ecosystem | `dependabot/infra/infrastructure-fc93691fd4` |
324+
325+
> [!NOTE]
326+
> For multi-ecosystem groups:
327+
> * The `pull-request-branch-name` on the `multi-ecosystem-groups` entry controls the grouped cross-ecosystem PR branch name.
328+
> * Individual `updates` entries that specify `multi-ecosystem-group` **cannot** have their own `pull-request-branch-name`. The group-level configuration takes precedence and is the only one used for those entries.
329+
> * `{package_manager}` is not available in multi-ecosystem group templates because the group spans multiple ecosystems.
330+
> * A content digest is always auto-appended to multi-ecosystem group branches to guarantee uniqueness.
331+
332+
### How branch name configuration applies
333+
334+
* **Configuration is per-update entry**: Each standalone `package-ecosystem` entry can have its own branch name configuration. Entries assigned to a multi-ecosystem group use the group-level configuration instead.
335+
* **Existing PRs are not affected**: Changes only apply to newly created PRs.
336+
* **Default behavior is unchanged**: If you don't configure any options, branch names remain exactly as they are today.
337+
338+
{% else %}
339+
220340
To maintain supportability or consistency with your existing processes, you may need to ensure your branch names align with your team's existing conventions. In this case, you can use `pull-request-branch-name.separator` to specify a different separator, choosing either `_`, `/`, or `"-"`.
221341

222342
In the below example, the npm configuration changes the default separator from `/` to `"-"`, so that it would appear as such:
@@ -235,13 +355,12 @@ updates:
235355
schedule:
236356
interval: "weekly"
237357
pull-request-branch-name:
238-
# Change the default separator (/) to a hyphen (-)
239358
separator: "-"
240359
```
241360

242-
{% data reusables.dependabot.option-affects-security-updates %}
361+
{% endif %}
243362

244-
See also [`pull-request-branch-name.separator`](/code-security/reference/supply-chain-security/dependabot-options-reference#pull-request-branch-nameseparator--).
363+
{% data reusables.dependabot.option-affects-security-updates %}
245364

246365
## Targeting pull requests against a non-default branch
247366

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Reference: Configurable branch name format options for Dependabot
2+
# Options: prefix, max-length, word-separator, branch-name-case, template
3+
versions:
4+
fpt: '*'
5+
ghec: '*'
6+
ghes: '> 3.22'

0 commit comments

Comments
 (0)