DevOps / Github Interview questions
What is the difference between GitHub Actions "on: pull_request" and "on: push" triggers?
on: push triggers a workflow whenever commits are pushed to a matching branch or tag, running against exactly the code that landed. on: pull_request triggers whenever a pull request is opened, updated, or reopened, and by default runs against a merge commit combining the PR's branch with its target branch, not just the PR branch in isolation.
on: push: branches: [main] pull_request: branches: [main] types: [opened, synchronize, reopened]
That default merge-commit behavior for pull_request is important: it means CI is actually testing what the code would look like after merging, catching integration issues a push-only trigger testing the branch alone would miss. It also means secrets are withheld by default for pull requests from forks, since a malicious fork PR shouldn't get access to a repository's secrets just by opening one, a restriction that plain push-triggered workflows on trusted branches don't need.
More Related questions...