4

When I use in my workflow github.ref_name it doesn't provide me a branch name from where I triggered this workflow. I get 16/merge. Why? When I use github.ref_type I clearly see that my ref type is branch so why I don't get branch name?

Also it's showing when I use $GITHUB_REF or git symbolic-ref HEAD (and separating refs/heads/ off). Ah and I tried github.event.push.ref but it's not showing me anything.

How to get always branch name from where I triggered the workflow?

TheTanadu
  • 554
  • 1
  • 7
  • 33
  • Note for a PR you can use `github.event.pull_request.head.ref` to get the branch name – shim Aug 05 '22 at 19:55

1 Answers1

4

For following code:

Run echo running on branch ${GITHUB_REF##*/} ${GITHUB_REF}

When your workflow runs becuase of push event you will get:

running on branch main refs/heads/main

But for pulr request event it would be:

running on branch merge refs/pull/3/merge

Why's that?

If the repository is on GitHub and you have any Pull Requests that have been opened, you’ll get these references that are prefixed with refs/pull/. These are basically branches, but since they’re not under refs/heads/ you don’t get them normally when you clone or fetch from the server — the process of fetching ignores them normally.

You can also check this question here

Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107