Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using env variable github.ref_name doesn't give me branch name

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?

like image 442
TheTanadu Avatar asked Aug 04 '26 23:08

TheTanadu


1 Answers

For following code:

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

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

running on branch main refs/heads/main

But for pull 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

like image 76
Krzysztof Madej Avatar answered Aug 07 '26 21:08

Krzysztof Madej



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!