How to trigger a GitHub workflow action on push to specific branches?

You can use “on” in your GitHub workflow file to automatically trigger GitHub workflow actions on every push to a specific branch.

Step 1: Create a personal access token in GitHub.

Step 2: Create a GitHub repository using REST API.

Step 3: Create a workflow definition for GitHub actions.

Note: We have used “on” with “push” and “branches” events to make GitHub automatically trigger GitHub workflow actions on every push to certain branches.

Step 4: Upload the workflow file and perform git push operations.

Observe: When we pushed to the master/main branch, no GitHub action was triggered as we have mentioned a specific branch name in the workflow file for the push event. Hence when we pushed to the “feature” branch a new Workflow action was triggered.

Step 5: Clean up.

Leave a Reply