Trigger Job on branch created

Hello, community.

I didn’t find documentation on how to trigger an action when I’m creating a branch.

What I want, on creating branch releases/** to trigger publish. Is it possible right now?

1 Like

When you push newly created branches to Github. You can watch on push events on the branch.

Hi @dmfilipenko ,

You can use the Create event to do this, mode details please reference here:
Note: When you create a new branch, in the branch which the new branch is based on, the YAML file for the Create event workflow must have been existing, otherwise the new branch will not trigger the workflow run.

I tried

      - releases/*


    types: [created]
      - 'releases/**'

But I am still seeing jobs getting triggered by non-release branches.


The create event does not support branch filter and tag filter. Anytime you create a new branch or tag, the workflow will be triggered as long as the workflow runs on create event has been existing on the base ref of the new branch or tag.

The push event does not have any Activity types. The activity type “created” you set on the push event does not exist.

If your projects really need the feature that the create event supports branch filter and tag filter, I recommend that you can directly report a feature request here. That will allow you to directly interact with the appropriate engineering team, and make it more convenient for the engineering team to collect and categorize your suggestions.

In addition, as the workaround, you can use the expression github.ref to get the name of the created branch from the github context, then add an if conditional on each job to skip all the jobs in the workflow according to the branch name.
For example:

on: create
    if: ${{ contains(github.ref, 'refs/heads/releases/') }}
    . . .
    if: ${{ contains(github.ref, 'refs/heads/releases/') }}
    . . .
    if: ${{ contains(github.ref, 'refs/heads/releases/') }}
    . . .

Thanks for this @brightran this is a really helpful workaround. I’ve submitted feedback from your link as there are still a few issues with this method, which I’ll just call out for anyone else who uses this method instead:

  1. The workflow still runs but just skips, instead of not running at all. This pollutes the workflow history with lots of meaningless workflow runs and makes it very difficult to find what you’re looking for (especially for the use-case of this example which I’m also using, which is for release build workflows that actually result in a release).
  2. The filter is not as accurate as you can’t specify a complex filter pattern. I was originally attempting to use release/[0-9]+.[0-9]+.[0-9]+ as a filter pattern to target release branches with a 3-part numerical version number. However, this workaround means that this will run on all release branches. Similarly I now can’t specify to not run on release branches that end in -rc in future without a very complex if statement here, for example.

It would be great for GitHub to add first-party support for this functionality as it would improve UX and help GitHub actions be a lot more flexible for power users, which would help to achieve feature parity with other build agent competitors and make it more attractive to enterprise users with very complex requirements.

We have also sent a feature request for branch filter suport on the create event at Share feedback - GitHub Support. Hopefully it will arrive soon, so that way the action will not be triggered every time any branch is created.

Is there any news regarding built-in support of branches filter by the create event?


no filter for branch yet? :frowning:

It would tremendously help us achieve our use-cases. I am voicing my concern for the delete event as well.

@dannevesdantas Where is the request you created ?

@staticnotdynamic we have sent it through the old customer feedback form page last year. Looks like the old customer feedback form doesn’t exists anymore and now feature requests should be send via the Discussions · github-community/community · GitHub repo, by opening a discussion. I believe my feature request was lost when the old customer feedback form was discontinued.

I have searched for past issues (now discussions) in the new tracker but I couldn’t find something similar to our case. Would you please paste your original proposal there as a discussion ?

If you did, please post back the discussion link so that we can all upvote it.