logo

Understanding GitHub actions branch rules for pull requests and pushes

A very important distinction

Joel Clermont
Joel Clermont
2025-11-10

In a GitHub actions workflow, you can specify branch rules to control when the workflow runs.

Two common triggers are pull_request and push. And both of these allow you to specify a list of branches to target, or a list of branches to ignore.

These configuration blocks look identical, but it's important to understand that they mean two very different things:

on:
  pull_request:
    branches-ignore:
      - develop
  push:
    branches:
      - develop

For some context, in this project, all feature branches are created off of develop. When a feature branch is ready, a pull request is opened to merge it into develop.

And when you're ready to release your work to production, a pull request is opened to merge develop into main.

So the intention with the above configuration was that it should be triggered anytime a pull request was merged into develop, which triggers the push event. And we did not want it to trigger when the pull request from develop into main was opened.

But this is not how it works! In the pull_request block, the branch names you list (either to include or ignore) are the base branch of the pull request and not the branch you are opening the pull request from as I mistakenly thought.

So this mistake actually disabled the workflow from running on any feature branch pull request that targeted develop.

To fix this, we need to change the pull_request block to this:

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

This is what we intended all along, and it now works as expected.

I wanted to share this gotcha because the configurations look similar on the surface, but they mean something quite different.

Here to help,

Joel

P.S. Have you checked out the Mastering Laravel community? You can learn from other developers and share what you know. Level up your skills!

Toss a coin in the jar if you found this helpful.
Want a tip like this in your inbox every weekday? Sign up below 👇🏼
email
No spam. Only real-world advice you can use.