When an action is set on pull_request
in Github Actions, how to get the target branch? The use case is to retrieve the PR- (and hopefully, branch)-specific commits.
Go to the pull request and click the ellipsis button and select Edit. From here you can change the target branch for the pr.
github.base_ref. string. The base_ref or target branch of the pull request in a workflow run. This property is only available when the event that triggers a workflow run is a pull_request .
Base Branch: The "Base Branch" is the branch where your new changes should be applied / integrated into. Head Branch: The "Head Branch" is the branch that contains the changes you want to integrate. Title: A short title that describes what this Pull Request is about.
You can access the target branch with ${{ github.event.pull_request.base.ref }}
.
To know the full list of properties of the github.event
object, try to run more $GITHUB_EVENT_PATH
.
Property name | Type | Description |
---|---|---|
github.base_ref |
string | The base_ref or target branch of the pull request in a workflow run. This property is only available when the event that triggers a workflow run is a pull_request . |
github.head_ref |
string | The head_ref or source branch of the pull request in a workflow run. This property is only available when the event that triggers a workflow run is a pull_request . |
An example (modified from the documentation):
steps:
- uses: actions/[email protected]
if: ${{ github.base_ref == 'main' }}
Environment variable | Description |
---|---|
GITHUB_HEAD_REF |
Only set for pull request events. The name of the head branch. |
GITHUB_BASE_REF |
Only set for pull request events. The name of the base branch. |
An example (modified from the documentation):
steps:
- name: Hello world
run: echo Hello world from $GITHUB_HEAD_REF!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With