What Is GITHUB_BASE_REF?
GITHUB_BASE_REF is the base (target) branch a pull request will merge into - set only for pull_request events.
GITHUB_BASE_REF tells a PR workflow where the change is headed, which is useful for computing diffs against the base branch or enforcing branch-specific rules.
Common uses
- Diff changed files against the base branch
- Apply stricter checks for PRs into
main - Pair with GITHUB_HEAD_REF for full PR context
Note
Computing a diff against the base usually needs full history, so set fetch-depth: 0 in actions/checkout.
Key takeaways
- GITHUB_BASE_REF is the PR target branch.
- Only set on pull_request events.
- Diffing against it needs fetch-depth: 0.
Related guides
What Is GITHUB_HEAD_REF?GITHUB_HEAD_REF is the source branch of a pull request in GitHub Actions. Learn when it is set and how to use…
What Is fetch-depth?What is fetch-depth in CI checkouts? Learn how this setting controls how much Git history a job fetches, why…
What Is a Pull Request?What is a pull request? An explainer on how PRs propose changes, gather review, run CI checks, and serve as t…