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
What Is GITHUB_BASE_REF?GITHUB_BASE_REF is the target branch of a pull request in GitHub Actions. Learn how it is used in diffs and m…
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…
What Is GITHUB_REF_NAME?GITHUB_REF_NAME is the short branch or tag name for a GitHub Actions run, like main or v1.2.0. Learn how it d…