dependabot
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDependabot Configuration & Management
Dependabot配置与管理
Overview
概述
Dependabot is GitHub's built-in dependency management tool with three core capabilities:
- Dependabot Alerts — Notify when dependencies have known vulnerabilities (CVEs)
- Dependabot Security Updates — Auto-create PRs to fix vulnerable dependencies
- Dependabot Version Updates — Auto-create PRs to keep dependencies current
All configuration lives in a single file: on the default branch. GitHub does not support multiple files per repository.
.github/dependabot.ymldependabot.ymlDependabot是GitHub内置的依赖管理工具,具备三大核心功能:
- Dependabot告警 — 当依赖存在已知漏洞(CVE)时发出通知
- Dependabot安全更新 — 自动创建PR修复存在漏洞的依赖
- Dependabot版本更新 — 自动创建PR以保持依赖为最新版本
所有配置都存储在默认分支的单个文件中:。GitHub不支持每个仓库存在多个文件。
.github/dependabot.ymldependabot.ymlConfiguration Workflow
配置流程
Follow this process when creating or optimizing a :
dependabot.yml创建或优化时,请遵循以下流程:
dependabot.ymlStep 1: Detect All Ecosystems
步骤1:检测所有生态系统
Scan the repository for dependency manifests. Look for:
| Ecosystem | YAML Value | Manifest Files |
|---|---|---|
| npm/pnpm/yarn | | |
| pip/pipenv/poetry/uv | | |
| Docker | | |
| Docker Compose | | |
| GitHub Actions | | |
| Go modules | | |
| Bundler (Ruby) | | |
| Cargo (Rust) | | |
| Composer (PHP) | | |
| NuGet (.NET) | | |
| .NET SDK | | |
| Maven (Java) | | |
| Gradle (Java) | | |
| Terraform | | |
| OpenTofu | | |
| Helm | | |
| Hex (Elixir) | | |
| Swift | | |
| Pub (Dart) | | |
| Bun | | |
| Dev Containers | | |
| Git Submodules | | |
| Pre-commit | | |
Note: pnpm and yarn both use the ecosystem value.
npm扫描仓库以查找依赖清单。需关注:
| 生态系统 | YAML值 | 清单文件 |
|---|---|---|
| npm/pnpm/yarn | | |
| pip/pipenv/poetry/uv | | |
| Docker | | |
| Docker Compose | | |
| GitHub Actions | | |
| Go modules | | |
| Bundler (Ruby) | | |
| Cargo (Rust) | | |
| Composer (PHP) | | |
| NuGet (.NET) | | |
| .NET SDK | | |
| Maven (Java) | | |
| Gradle (Java) | | |
| Terraform | | |
| OpenTofu | | |
| Helm | | |
| Hex (Elixir) | | |
| Swift | | |
| Pub (Dart) | | |
| Bun | | |
| Dev Containers | | |
| Git Submodules | | |
| Pre-commit | | |
注意:pnpm和yarn均使用作为生态系统值。
npmStep 2: Map Directory Locations
步骤2:映射目录位置
For each ecosystem, identify where manifests live. Use (plural) with glob patterns for monorepos:
directoriesyaml
directories:
- "/" # root
- "/apps/*" # all app subdirs
- "/packages/*" # all package subdirs
- "/lib-*" # dirs starting with lib-
- "**/*" # recursive (all subdirs)Important: (singular) does NOT support globs. Use (plural) for wildcards.
directorydirectories针对每个生态系统,确定清单文件的存储位置。对于单体仓库,使用(复数形式)和通配符模式:
directoriesyaml
directories:
- "/" # 根目录
- "/apps/*" # 所有应用子目录
- "/packages/*" # 所有包子目录
- "/lib-*" # 以lib-开头的目录
- "**/*" # 递归(所有子目录)重要提示:(单数形式)不支持通配符。如需使用通配符,请使用(复数形式)。
directorydirectoriesStep 3: Configure Each Ecosystem Entry
步骤3:配置每个生态系统条目
Every entry needs at minimum:
yaml
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"每个条目至少需要包含以下内容:
yaml
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"Step 4: Optimize with Grouping, Labels, and Scheduling
步骤4:通过分组、标签和调度进行优化
See sections below for each optimization technique.
请查看以下各节了解每种优化技术。
Monorepo Strategies
单体仓库策略
Glob Patterns for Workspace Coverage
工作区覆盖的通配符模式
For monorepos with many packages, use glob patterns to avoid listing each directory:
yaml
- package-ecosystem: "npm"
directories:
- "/"
- "/apps/*"
- "/packages/*"
- "/services/*"
schedule:
interval: "weekly"对于包含多个包的单体仓库,使用通配符模式避免逐个列出目录:
yaml
- package-ecosystem: "npm"
directories:
- "/"
- "/apps/*"
- "/packages/*"
- "/services/*"
schedule:
interval: "weekly"Cross-Directory Grouping
跨目录分组
Use to create a single PR when the same dependency updates across multiple directories:
group-by: dependency-nameyaml
groups:
monorepo-deps:
group-by: dependency-nameThis creates one PR per dependency across all specified directories, reducing CI costs and review burden.
Limitations:
- All directories must use the same package ecosystem
- Applies to version updates only
- Incompatible version constraints create separate PRs
使用在同一依赖在多个目录中更新时创建单个PR:
group-by: dependency-nameyaml
groups:
monorepo-deps:
group-by: dependency-name这会针对所有指定目录中的同一依赖创建一个PR,减少CI成本和审核负担。
限制:
- 所有目录必须使用相同的包生态系统
- 仅适用于版本更新
- 不兼容的版本约束会创建单独的PR
Standalone Packages Outside Workspaces
工作区外的独立包
If a directory has its own lockfile and is NOT part of the workspace (e.g., scripts in ), create a separate ecosystem entry for it.
.github/如果某个目录有自己的锁文件且不属于工作区(例如中的脚本),请为其创建单独的生态系统条目。
.github/Dependency Grouping
依赖分组
Reduce PR noise by grouping related dependencies into single PRs.
通过将相关依赖分组到单个PR中来减少PR数量。
By Dependency Type
按依赖类型分组
yaml
groups:
dev-dependencies:
dependency-type: "development"
update-types: ["minor", "patch"]
production-dependencies:
dependency-type: "production"
update-types: ["minor", "patch"]yaml
groups:
dev-dependencies:
dependency-type: "development"
update-types: ["minor", "patch"]
production-dependencies:
dependency-type: "production"
update-types: ["minor", "patch"]By Name Pattern
按名称模式分组
yaml
groups:
angular:
patterns: ["@angular*"]
update-types: ["minor", "patch"]
testing:
patterns: ["jest*", "@testing-library*", "ts-jest"]yaml
groups:
angular:
patterns: ["@angular*"]
update-types: ["minor", "patch"]
testing:
patterns: ["jest*", "@testing-library*", "ts-jest"]For Security Updates
针对安全更新分组
yaml
groups:
security-patches:
applies-to: security-updates
patterns: ["*"]
update-types: ["patch", "minor"]Key behaviors:
- Dependencies matching multiple groups go to the first match
- defaults to
applies-towhen absentversion-updates - Ungrouped dependencies get individual PRs
yaml
groups:
security-patches:
applies-to: security-updates
patterns: ["*"]
update-types: ["patch", "minor"]关键行为:
- 匹配多个组的依赖会归到第一个匹配的组
- 若未指定,默认值为
applies-toversion-updates - 未分组的依赖会生成单独的PR
Multi-Ecosystem Groups
多生态系统分组
Combine updates across different package ecosystems into a single PR:
yaml
version: 2
multi-ecosystem-groups:
infrastructure:
schedule:
interval: "weekly"
labels: ["infrastructure", "dependencies"]
updates:
- package-ecosystem: "docker"
directory: "/"
patterns: ["nginx", "redis"]
multi-ecosystem-group: "infrastructure"
- package-ecosystem: "terraform"
directory: "/"
patterns: ["aws*"]
multi-ecosystem-group: "infrastructure"The key is required when using .
patternsmulti-ecosystem-group将不同包生态系统的更新合并到单个PR中:
yaml
version: 2
multi-ecosystem-groups:
infrastructure:
schedule:
interval: "weekly"
labels: ["infrastructure", "dependencies"]
updates:
- package-ecosystem: "docker"
directory: "/"
patterns: ["nginx", "redis"]
multi-ecosystem-group: "infrastructure"
- package-ecosystem: "terraform"
directory: "/"
patterns: ["aws*"]
multi-ecosystem-group: "infrastructure"使用时必须指定键。
multi-ecosystem-grouppatternsPR Customization
PR自定义
Labels
标签
yaml
labels:
- "dependencies"
- "npm"Set to disable all labels including defaults. SemVer labels (, , ) are always applied if present in the repo.
labels: []majorminorpatchyaml
labels:
- "dependencies"
- "npm"设置可禁用所有标签(包括默认标签)。如果仓库中存在SemVer标签(、、),则始终会自动应用这些标签。
labels: []majorminorpatchCommit Messages
提交信息
yaml
commit-message:
prefix: "deps"
prefix-development: "deps-dev"
include: "scope" # adds deps/deps-dev scope after prefixyaml
commit-message:
prefix: "deps"
prefix-development: "deps-dev"
include: "scope" # 在前缀后添加deps/deps-dev范围Assignees and Milestones
指派人与里程碑
yaml
assignees: ["security-team-lead"]
milestone: 4 # numeric ID from milestone URLyaml
assignees: ["security-team-lead"]
milestone: 4 # 里程碑URL中的数字IDBranch Name Separator
分支名称分隔符
yaml
pull-request-branch-name:
separator: "-" # default is /yaml
pull-request-branch-name:
separator: "-" # 默认值为/Target Branch
目标分支
yaml
target-branch: "develop" # PRs target this instead of default branchNote: When is set, security updates still target the default branch; all ecosystem config only applies to version updates.
target-branchyaml
target-branch: "develop" # PR将以此分支为目标,而非默认分支注意:当设置后,安全更新仍会以默认分支为目标;所有生态系统配置仅适用于版本更新。
target-branchSchedule Optimization
调度优化
Intervals
间隔
Supported: , , , , , ,
dailyweeklymonthlyquarterlysemiannuallyyearlycronyaml
schedule:
interval: "weekly"
day: "monday" # for weekly only
time: "09:00" # HH:MM format
timezone: "America/New_York"支持的间隔:、、、、、、
dailyweeklymonthlyquarterlysemiannuallyyearlycronyaml
schedule:
interval: "weekly"
day: "monday" # 仅适用于每周调度
time: "09:00" # HH:MM格式
timezone: "America/New_York"Cron Expressions
Cron表达式
yaml
schedule:
interval: "cron"
cronjob: "0 9 * * 1" # Every Monday at 9 AMyaml
schedule:
interval: "cron"
cronjob: "0 9 * * 1" # 每周一上午9点Cooldown Periods
冷却期
Delay updates for newly released versions to avoid early-adopter issues:
yaml
cooldown:
default-days: 5
semver-major-days: 30
semver-minor-days: 7
semver-patch-days: 3
include: ["*"]
exclude: ["critical-lib"]Cooldown applies to version updates only, not security updates.
延迟更新新版本,以避免早期采用者遇到问题:
yaml
cooldown:
default-days: 5
semver-major-days: 30
semver-minor-days: 7
semver-patch-days: 3
include: ["*"]
exclude: ["critical-lib"]冷却期仅适用于版本更新,不适用于安全更新。
Security Updates Configuration
安全更新配置
Enable via Repository Settings
通过仓库设置启用
Settings → Advanced Security → Enable Dependabot alerts, security updates, and grouped security updates.
设置 → 高级安全 → 启用Dependabot告警、安全更新和分组安全更新。
Group Security Updates in YAML
在YAML中分组安全更新
yaml
groups:
security-patches:
applies-to: security-updates
patterns: ["*"]
update-types: ["patch", "minor"]yaml
groups:
security-patches:
applies-to: security-updates
patterns: ["*"]
update-types: ["patch", "minor"]Disable Version Updates (Security Only)
禁用版本更新(仅保留安全更新)
yaml
open-pull-requests-limit: 0 # disables version update PRsyaml
open-pull-requests-limit: 0 # 禁用版本更新PRAuto-Triage Rules
自动分类规则
GitHub presets auto-dismiss low-impact alerts for development dependencies. Custom rules can filter by severity, package name, CWE, and more. Configure in repository Settings → Advanced Security.
GitHub预设会自动关闭对开发依赖的低影响告警。可根据严重性、包名称、CWE等配置自定义规则。在仓库设置 → 高级安全中进行配置。
PR Comment Commands
PR评论命令
Interact with Dependabot PRs using comments.
@dependabotNote: As of January 2026, merge/close/reopen commands have been deprecated. Use GitHub's native UI, CLI (), or auto-merge instead.gh pr merge
| Command | Effect |
|---|---|
| Rebase the PR |
| Recreate the PR from scratch |
| Close and never update this dependency |
| Ignore this major version |
| Ignore this minor version |
| Ignore this patch version |
For grouped PRs, additional commands:
- — ignore specific dependency in group
@dependabot ignore DEPENDENCY_NAME - — clear ignores, reopen with updates
@dependabot unignore DEPENDENCY_NAME - — clear all ignores for all dependencies in group
@dependabot unignore * - — display current ignores
@dependabot show DEPENDENCY_NAME ignore conditions
For the complete command reference, see .
references/pr-commands.md使用评论与Dependabot PR进行交互。
@dependabot注意: 截至2026年1月,合并/关闭/重新打开命令已被弃用。请使用GitHub原生UI、CLI()或自动合并功能。gh pr merge
| 命令 | 效果 |
|---|---|
| 对PR执行变基操作 |
| 从头重新创建PR |
| 关闭PR且不再更新该依赖 |
| 忽略该主版本 |
| 忽略该次版本 |
| 忽略该补丁版本 |
对于分组PR,还有以下额外命令:
- — 忽略组中的特定依赖
@dependabot ignore DEPENDENCY_NAME - — 清除忽略设置,重新打开包含更新的PR
@dependabot unignore DEPENDENCY_NAME - — 清除组中所有依赖的忽略设置
@dependabot unignore * - — 显示当前的忽略条件
@dependabot show DEPENDENCY_NAME ignore conditions
完整命令参考请查看。
references/pr-commands.mdIgnore and Allow Rules
忽略与允许规则
Ignore Specific Dependencies
忽略特定依赖
yaml
ignore:
- dependency-name: "lodash"
- dependency-name: "@types/node"
update-types: ["version-update:semver-patch"]
- dependency-name: "express"
versions: ["5.x"]yaml
ignore:
- dependency-name: "lodash"
- dependency-name: "@types/node"
update-types: ["version-update:semver-patch"]
- dependency-name: "express"
versions: ["5.x"]Allow Only Specific Types
仅允许特定类型
yaml
allow:
- dependency-type: "production"
- dependency-name: "express"Rule: If a dependency matches both and , it is ignored.
allowignoreyaml
allow:
- dependency-type: "production"
- dependency-name: "express"规则:如果某个依赖同时匹配和规则,则该依赖会被忽略。
allowignoreExclude Paths
排除路径
yaml
exclude-paths:
- "vendor/**"
- "test/fixtures/**"yaml
exclude-paths:
- "vendor/**"
- "test/fixtures/**"Advanced Options
高级选项
Versioning Strategy
版本控制策略
Controls how Dependabot edits version constraints:
| Value | Behavior |
|---|---|
| Default — increase for apps, widen for libraries |
| Always increase minimum version |
| Only change if current range excludes new version |
| Only update lockfiles, ignore manifests |
| Widen range to include both old and new versions |
控制Dependabot如何编辑版本约束:
| 值 | 行为 |
|---|---|
| 默认值 — 针对应用程序提升版本,针对库放宽版本范围 |
| 始终提升最低版本 |
| 仅当当前版本范围不包含新版本时才进行更改 |
| 仅更新锁文件,忽略清单文件 |
| 放宽版本范围以同时包含旧版本和新版本 |
Rebase Strategy
变基策略
yaml
rebase-strategy: "disabled" # stop auto-rebasingAllow rebase over extra commits by including in commit messages.
[dependabot skip]yaml
rebase-strategy: "disabled" # 停止自动变基在提交信息中包含,允许在额外提交上执行变基操作。
[dependabot skip]Open PR Limit
打开PR数量限制
yaml
open-pull-requests-limit: 10 # default is 5 for version, 10 for securitySet to to disable version updates entirely.
0yaml
open-pull-requests-limit: 10 # 版本更新默认值为5,安全更新默认值为10设置为可完全禁用版本更新。
0Private Registries
私有仓库
yaml
registries:
npm-private:
type: npm-registry
url: https://npm.example.com
token: ${{secrets.NPM_TOKEN}}
updates:
- package-ecosystem: "npm"
directory: "/"
registries:
- npm-privateyaml
registries:
npm-private:
type: npm-registry
url: https://npm.example.com
token: ${{secrets.NPM_TOKEN}}
updates:
- package-ecosystem: "npm"
directory: "/"
registries:
- npm-privateFAQ
常见问题
Can I have multiple files?
No. GitHub supports exactly one file at . Use multiple entries within that file for different ecosystems and directories.
dependabot.yml.github/dependabot.ymlupdatesDoes Dependabot support pnpm?
Yes. Use — Dependabot detects automatically.
package-ecosystem: "npm"pnpm-lock.yamlHow do I reduce PR noise in a monorepo?
Use to batch updates, with globs for coverage, and for cross-directory grouping. Consider or intervals for low-priority ecosystems.
groupsdirectoriesgroup-by: dependency-namemonthlyquarterlyHow do I handle dependencies outside the workspace?
Create a separate ecosystem entry with its own pointing to that location.
directory我可以拥有多个文件吗?
不可以。GitHub仅支持在路径下存在一个文件。可在该文件中使用多个条目来配置不同的生态系统和目录。
dependabot.yml.github/dependabot.ymlupdatesDependabot支持pnpm吗?
支持。使用 — Dependabot会自动检测文件。
package-ecosystem: "npm"pnpm-lock.yaml如何减少单体仓库中的PR数量?
使用批量处理更新,使用带通配符的覆盖所有目录,使用进行跨目录分组。对于低优先级生态系统,可考虑使用或的更新间隔。
groupsdirectoriesgroup-by: dependency-namemonthlyquarterly如何处理工作区外的依赖?
创建单独的生态系统条目,将其指向该位置。
directoryResources
资源
- — Complete YAML options reference
references/dependabot-yml-reference.md - — Full PR comment commands reference
references/pr-commands.md - — Real-world configuration examples
references/example-configs.md
- — 完整YAML选项参考
references/dependabot-yml-reference.md - — 完整PR评论命令参考
references/pr-commands.md - — 真实场景配置示例
references/example-configs.md