I’ve recently had to get the current branch or the target branch of a PR in Github actions. It took a bit of researching, so I thought it’s worth sharing.

The code below will get the short branch name if the trigger was a push or pull request.

Push request contains the full HEAD of the branch ${GITHUB_REF##*/} will extract only the short name.

After the step runs, you can access the branch name by calling

${{ steps.extract_branch.outputs.branch }} while in the same job.

If you need to pass that value between jobs, add an outputs block to job1, add a needs block to job2.

You can access the value in job2 by accessing the value in

${{ needs.job1.outputs.extract_branch }}

See the example below.

passing outputs between jobs

Philip Chyla


Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store