Course contentsShow
← Cloud and Infrastructure
Lesson 1698 of 2,98935. GitHub ActionsFree lesson

Workflow Triggers: Push and Pull Request

Configure workflows to run on push and pull request events with branch and path filters.

Workflow Triggers: Push and Pull Request

What you'll learn: How to configure GitHub Actions workflows to automatically run when code is pushed or pull requests are opened, with precise control over which branches and files trigger execution.

Understanding Workflow Triggers

Workflow triggers define when your automation runs. The most common triggers are push (when code is pushed to a branch) and pull_request (when a PR is opened, updated, or synchronized). Think of triggers like motion sensors that activate lights—they detect specific events and spring your workflow into action.

Basic Trigger Configuration

In your workflow YAML file, the on: key specifies triggers:

on:
  push:
    branches:
      - main
      - develop
  pull_request:
    branches:
      - main

This workflow runs when code is pushed to main or develop, and when PRs target main.

Branch Filtering

You can filter by branch patterns using wildcards:

on:
  push:
    branches:
      - 'feature/**'  # Any branch starting with feature/
      - '!feature/experimental'  # Exclude this branch

Path Filtering

Run workflows only when specific files change:

on:
  push:
    paths:
      - 'src/**'
      - 'Dockerfile'
    paths-ignore:
      - 'docs/**'
      - '**.md'

This triggers only if source code or the Dockerfile changes, ignoring documentation updates.

Combining Filters

Branch and path filters work together—both conditions must match:

on:
  pull_request:
    branches:
      - main
    paths:
      - 'api/**'

This runs only for PRs targeting main that modify the api directory.

Key Takeaway: Workflow triggers with branch and path filters give you precise control over when automation runs, reducing unnecessary builds and focusing CI/CD resources where they matter most.