Quickstart Guide
Get MergeGuard running in your repository in under 5 minutes.
Step 1: Install the GitHub App
- Go to MergeGuard on GitHub Marketplace
- Click “Install”
- Select the repositories you want to enable
- Authorize the app
Required Permissions:
contents: write(for auto-merge)pull_requests: write(for comments and reviews)checks: write(for Check Runs)
Step 2: Create Configuration File
Add .github/mergeguard.yml to your repository:
rules:
- name: "Default policy"
require:
approvals: 1
Commit and push this file to your repository.
Step 3: Open a Pull Request
MergeGuard will automatically:
- Evaluate the PR against your rules
- Create a GitHub Check Run showing requirements
- Update the check as approvals/changes happen
That’s it! You now have basic PR automation running.
Understanding the Flow
1. GitHub Triggers MergeGuard
When a PR is opened, updated, or reviewed, GitHub sends a webhook event to MergeGuard.
2. MergeGuard Builds Context
Collects information about the PR:
- Files changed (paths)
- Lines of code added/deleted
- PR author
- Labels
- Existing approvals
- Semver level (for Dependabot PRs)
- Dependencies (via
Depends on #123syntax)
3. Rules Are Evaluated
Each rule’s if conditions are checked against the PR context. All conditions must match (AND logic).
4. Priority Selection
If multiple rules match:
- Only rules with the highest priority (lowest number) are enforced
- Multiple rules with the same priority are all enforced
- Default priority is
100
5. GitHub Check Run Created
MergeGuard creates/updates a Check Run showing:
- Which rules matched
- What requirements are needed
- Current approval status
- Which checks must pass
6. Actions Execute
If configured:
autoApprove: MergeGuard leaves an approvalautoMerge: When requirements are met, PR is merged
Rule Structure Basics
Every rule has four optional sections:
- name: "Rule name" # Required
description: "Why this rule exists" # Optional but recommended
priority: 50 # Optional (default: 100, lower = higher priority)
if: # Conditions: when does this rule apply?
maxLocChanged: 100
paths: ["src/**"]
excludePaths: ["test/**"]
author: "dependabot[bot]"
semverLevel: "patch"
labels: ["urgent"]
require: # Requirements: what must be satisfied?
approvals: 2
teams: ["platform-team"]
users: ["tech-lead"]
checks: ["unit-tests", "security-scan"]
action: # Actions: what should happen automatically?
autoApprove: true
autoMerge:
requireChecks: true
mergeMethod: "squash"
Key Points:
ifsection: all conditions must match (AND logic)requiresection: all requirements must be satisfiedactionsection: executed when rule matches and requirements are met
Common Starter Configurations
Fast-Track Small Changes
- name: "Small changes"
if:
maxLocChanged: 10
excludePaths:
- "infra/**"
- ".github/workflows/**"
require:
approvals: 1
action:
autoApprove: true
Protect Critical Paths
- name: "Infrastructure changes"
priority: 10
if:
paths:
- "infra/**"
- ".github/workflows/**"
require:
approvals: 2
teams: ["platform-team"]
checks:
- "terraform-validate"
- "security-scan"
Auto-Merge Dependabot Patches
- name: "Dependabot patches"
if:
author: "dependabot[bot]"
semverLevel: ["patch", "minor"]
require:
checks: ["security-scan"]
action:
autoApprove: true
autoMerge:
requireChecks: true
mergeMethod: "squash"
Skip CI for Documentation
- name: "Documentation only"
if:
paths: ["docs/**"]
excludePaths: ["src/**"]
require:
approvals: 1
# No checks required - saves CI costs!
Combined Example
rules:
# High priority: Emergency fixes
- name: "Emergency hotfix"
priority: 10
if:
labels: ["hotfix"]
require:
approvals: 1
users: ["incident-commander"]
action:
autoMerge:
requireChecks: true
# Medium priority: Infrastructure
- name: "Infrastructure"
priority: 50
if:
paths: ["infra/**"]
require:
approvals: 2
teams: ["platform-team", "security-team"]
# Default: Everything else
- name: "Default policy"
priority: 100
require:
approvals: 2
Validation
Before pushing your config, validate it locally:
yarn validate:config
For IDE validation, add this to the top of your YAML file:
# yaml-language-server: $schema=https://raw.githubusercontent.com/MergeGuard/mergeguard-app/main/schema/mergeguard.schema.json
rules:
- name: "..."
What Happens When…
A Rule Matches
✅ MergeGuard creates a Check Run showing requirements
✅ If autoApprove is set, an approval is added
✅ When requirements are met and autoMerge is set, PR merges
No Rules Match
⚠️ MergeGuard creates a Check Run with status “No matching rules”
⚠️ PR is not blocked but has no specific requirements enforced
Multiple Rules Match (Same Priority)
✅ All matching rules with the highest priority are enforced
✅ Requirements are combined (all must be satisfied)
Multiple Rules Match (Different Priorities)
✅ Only rules with the highest priority (lowest number) are enforced
✅ Lower priority rules are ignored
Next Steps
Now that you have the basics:
- Explore Features - Learn about all available capabilities:
- Start Simple - Begin with a default rule, add complexity as needed
- Test Incrementally - Add one rule at a time and observe behavior
- Monitor Effectiveness - Track which rules match most often
Getting Help
- Check Run Details - Click the MergeGuard check to see evaluation details
- Validation Errors - Run
yarn validate:configfor schema validation - GitHub Issues - Report bugs or request features