GitHub Actions - Add and Commit file to repo

by
Jeremy Canfield |
Updated: December 20 2024
| GitHub Actions articles
GitHub Actions can be used to do something whenever something happens in one of your GitHub repositories. If you are not familiar with GitHub Actions, check out my article Getting Started with GitHub Actions.
Let's say you create a file in your runner VM and you want to add and commit the file to your repo.
name: GitHub Action
run-name: ${{ github.workflow }} run by ${{ github.actor }}
on:
push:
branches:
- main
jobs:
github-action-job:
runs-on: ubuntu-latest
steps:
- name: Checking out the repository code
uses: actions/checkout@v4
- name: create foo.txt
run: touch foo.txt
- name: git config user.name
run: git config user.name "github-actions"
- name: git config user.email
run: git config user.email "github-actions@example.com"
- name: git add foo.txt to repo
run: git add foo.txt
- name: git commit foo.txt
run: git commit -m 'initial commit' foo.txt
- name: git push origin HEAD
run: git push origin HEAD
Did you find this article helpful?
If so, consider buying me a coffee over at