Skip to content
Latchkey

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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →