How to commit to repository via GitHub Actions?

Hello everyone! I want to create (or overwrite) in remote repo new file in the root folder named HelloWorld.txt when new issue is created. How to implement it?

# This is a basic workflow to help you get started with Actions

name: CI

on: issues

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v2

      # Runs a set of commands using the runners shell
      - name: Run a multi-line script
        run: |
          git config --global user.email "AlvinSeville7cf@gmail.com"
          git config --global user.name "Alvin Seville"
          echo "Hello world!" > HelloWorld.txt
          git add HelloWorld.txt && git commit -m "HelloWorld.txt"

I want to see new commit in commit list:

You’ve got most of it. Username doesn’t look right (credential not display name). You’ll need to setup a PAT or token that has permission on the destination repo. Then push in the end.
git push origin/master, git push upstream/master, whatever.

1 Like

@alvin-seville ,
The current commands you have set only can commit the changes to the local repository. The “git push” command should be added at the end, so that the new commit can be pushed from the local repository to the remote repository.

- name: commit and push new changes
  run: |
    echo "Hello world!" > HelloWorld.txt

    git config --global user.email "your email"
    git config --global user.name "your username"

    git add HelloWorld.txt
    git commit -m "commit message"
    git push
2 Likes

You can use the excellent “github-push-action” written by @ad-m https://github.com/ad-m/github-push-action. I used it here for example to push changes to orphaned branches of my own repository, but it can be used to push to another repository if you have “personal access token”:
https://github.com/apache/airflow/blob/92eafc01ed08ebb5f0ce5e38567c611ada3649fc/.github/workflows/ci.yml#L727

@alvin-seville ,

How are things going?
Is the suggestion that adding the “git push” command helpful to you?
Please try it to see if ii works. If you have any update, feel free to the us.