Skip to content

Default Branch should be triggered branch not Master #38

Closed

Description

@Snazzie

The reason for this is because i was having hair pulling troubles trying to figure out how to get this action to push to the branch that triggered the script. Due to the complexity of github actions.

In addition, this Action name's "intent" is just push, which by default I would expect it to only push on the triggered branch, not merge to master.

Either it should by default push to trigger branch or give the example to do so in the readme file.

      uses: ad-m/github-push-action@master
      with:
        github_token: ${{ secrets.GITHUB_TOKEN }}
        branch: ${{ github.head_ref }}

Activity

  1. DavidGOrtega commented on Dec 18, 2019

    @DavidGOrtega

    or

    branch=${GITHUB_REF#refs/heads/} 

    inside your action

  2. koppor commented on Jan 2, 2020

    @koppor
    Contributor

    +1 for defaulting to current branch. I like the solution by @DavidGOrtega. Could you please update the code and the README.md accordingly?

  3. Snazzie commented on Jan 2, 2020

    @Snazzie
    Author

    Out of curiosity, is there a difference between ${{ github.head_ref }} and ${GITHUB_REF#refs/heads/}?

  4. koppor commented on Jan 2, 2020

    @koppor
    Contributor

    The former is for the .yml file (Syntax: GitHub Actions), the latter is inside https://github.com/ad-m/github-push-action/blob/master/start.sh (Syntax: Bash).

    The advantage of the latter approach is that the script will also work when triggered in a push. Otherwise, it will only work in a pull_request event. (As far as I did not do something wrong in my experiements this morning. There, the variable github.head_ref was empty in the case of a push event)

  5. Snazzie commented on Jan 2, 2020

    @Snazzie
    Author

    The former is for the .yml file (Syntax: GitHub Actions), the latter is inside https://github.com/ad-m/github-push-action/blob/master/start.sh (Syntax: Bash).

    Ahh fair enough

    The advantage of the latter approach is that the script will also work when triggered in a push. Otherwise, it will only work in a pull_request event. (As far as I did not do something wrong in my experiements this morning. There, the variable github.head_ref was empty in the case of a push event)

    The former works for push for me. See action script.

    Heres a screenshot of github action trigger that was successful in committing to master from a push onto master.
    Screenshot from Gyazo

  6. Snazzie commented on Jan 2, 2020

    @Snazzie
    Author

    Do you know if an empty HEAD: defaults to master?
    If so then thats probably how mine is working and my script isnt doing what i think its doing 😅.
    im not familiar with git command line.

  7. jcislinsky commented on Jan 31, 2020

    @jcislinsky

    I set our CI to use this plugin to push only tags. So I didn't set branch and I thought that it will push only tags. But a very weird thing happened. Every time our workflow finished a deploy from any branch it 'force' pushes the current branch to the master. 😲

    Maybe I did not read the documentation properly but I still think that if I don't specify the branch, it should push to the current or doesn't push branch at all.

  8. Gummibeer commented on Feb 8, 2020

    @Gummibeer

    @koppor

    The former is for the .yml file (Syntax: GitHub Actions), the latter is inside https://github.com/ad-m/github-push-action/blob/master/start.sh (Syntax: Bash).

    The advantage of the latter approach is that the script will also work when triggered in a push. Otherwise, it will only work in a pull_request event. (As far as I did not do something wrong in my experiements this morning. There, the variable github.head_ref was empty in the case of a push event)

    You can use the ref instead of head_ref for push events.
    https://help.github.com/en/actions/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#github-context

  9. added a commit that references this issue on May 8, 2020
  10. yasirroni commented on Apr 14, 2022

    @yasirroni

    branch: ${{ github.head_ref }} is to change on which branch it comes from. How to make it push on the committer fork instead of the upstream on pull request?

  11. ZPascal commented on Apr 16, 2022

    @ZPascal
    Collaborator

    Hi @yasirroni,

    if understand your question correctly, you wanna push inside an PR scenario in the fork, correct?
    You can try the following parameters:

    branch: '${{ github.event.pull_request.head.repo.default_branch }}'
    repository: '${{ github.event.pull_request.head.repo.full_name }}'
  12. ZPascal commented on May 23, 2026

    @ZPascal
    Collaborator

    I'll close the issue. The configuration is already documented inside the README.md.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions