Skip to content

CICD-002 · Limit pushes to main ​

Encyclopedia · Events and triggers · All snippets

Previous · CICD-001 · Next · CICD-003

1. Where it fits ​

  • Placement .github/workflows/ci.yml, at workflow level, or within jobs for a named job mapping.
  • Prerequisites workflow on an example repository with main as default.
  • Platforms github-actions, gitea-actions.

2. Copy the snippet ​

yaml
on:
  push:
    branches: [main]

3. How it works ​

The push event supplies the ref that was updated. A branches filter keeps only the named branch, even though the same file may exist elsewhere.

4. Verify the result ​

Push to main and a feature branch. Only the former should trigger.

Watch for. Place event filters at workflow scope and test an event that should run and an event that should be skipped.

Validation syntax-validated (YAML parse). Status definitions.