'How to update/cherry-pick other branches on push on specified branch?

I would like to create GitHub action that is triggered by push on specified branch X. This action will push/cherry-pick changes made on branch X to other branches.

Example code:

name: Cherry-pick

on:
  push:
      branches: [X]


jobs:
  cherry-pick:
    runs-on: [X-runner]
    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0
          ref: 'X-branch'
      - name: Cherry-pick X-branch changes
        run: |
          for branch in $(git branch -a | grep -e chosenBranches*);
            do
              git checkout $branch
              git cherry-pick X-branch
              git push -f
            done

Any ideas how to build such action?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source