63

This question refers to this: https://github.com/features/actions

I have written a GitHub action to build my code and create a production bundle. I'd like to have that included into my repository by committing the changes to origin/master. This seems like an obvious feature for GitHub actions to have but I can't find it anywhere. How do I commit changes with a GitHub action and push them?

1
  • 4
    First of all, they're not duplicates. Mine discusses how to commit and push, not just push. Secondly, mine predates that question by about 4 months.
    – Ben Cooper
    Oct 5, 2019 at 18:20

3 Answers 3

40

Update: Please see the following question/answer for full details about how to push changes back to the remote. Push to origin from GitHub action

An alternative option is create-pull-request action. It will automatically commit changes to a new branch and raise a pull request for you to review the changes. I wrote a detailed explanation about it as an answer to another question here: https://stackoverflow.com/a/58004257/11934042

18

I found the stefanzweifel/git-auto-commit-action to be the best solution. It's really as easy as:

- uses: stefanzweifel/git-auto-commit-action@v4

One could, of course, tune the parameters, like commit message, file globs and many others.

7
  • Note that this doesn't work for repos owned by an organization: Error: .github#L1 stefanzweifel/git-auto-commit-action@v5 is not allowed to be used in <your organization> /<your repository>. Actions in this workflow must be: within a repository owned by <your organization> or created by GitHub. Nov 16 at 22:49
  • 1
    Blame your organization, not this action. The error clearly says what's the problem. docs.github.com/en/organizations/managing-organization-settings/…
    – madhead
    Nov 17 at 10:09
  • Hi madhead, I didn't say anything about blame? This is useful information for others. Best regards, Nov 17 at 18:07
  • You said precisely "this doesn't work for repos owned by an organization". But it's not "this" that does not work, it's your organization security settings. It has nothing to do with this particular action. Any other action outside or you org or actions repos would not work for you. That's completely off-topic for the question asked.
    – madhead
    Nov 17 at 22:03
  • I disagree. It doesn't matter whose fault it is. Users are coming here for a solution to this question and many will run into the same issue. Best regards, Nov 18 at 5:33
2

The easiest way to do this is to just integrate this action: https://github.com/cds-snc/github-actions/tree/master/auto-commit

It's a little frustrating because it has a default name/email that's ridiculous so you have to fork it to fix it but it otherwise works well.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.