Skip to content
Latchkey

What Is GITHUB_HEAD_REF?

GITHUB_HEAD_REF is the head (source) branch name of a pull request - set only for pull_request events.

On a pull_request run, GITHUB_HEAD_REF is the branch the PR comes from, while GITHUB_BASE_REF is the branch it targets. It is empty for push events.

When it is set

Only on pull_request and pull_request_target events. On push events it is empty.

Example

Build a preview named after the PR branch.

shell
echo "Building PR from ${GITHUB_HEAD_REF}"

Key takeaways

  • GITHUB_HEAD_REF is the PR source branch.
  • It is only set on pull_request events.
  • Pairs with GITHUB_BASE_REF (the target branch).

Related guides

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