Skip to content

About

Github action which lets you to commit and push a file to a repository

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

github-commit-push-file View Action pipeline

maxgfr/github-commit-push-file is a GitHub Action which lets you commit and push files to a repository with advanced options like commit signing, custom author, selective file staging, PR creation, and more.

Features

  • Commit and push files to a repository
  • GPG commit signing support with enhanced validation
  • Custom author name and email
  • Selective file staging (specific files, glob patterns, quoted paths with spaces)
  • Exclude files from staging (e.g. *.env)
  • Read file list from a file (pathspec_from_file)
  • Target branch configuration with automatic branch creation
  • Skip if no changes / allow empty commits
  • Force push and push retry on conflict with automatic rebase
  • Amend previous commit
  • Create tags (lightweight and annotated)
  • Create pull requests with labels and draft support
  • Template variables in commit messages ({{date}}, {{sha}}, {{branch}}, etc.)
  • Custom commit timestamp
  • Dry run mode
  • Multi-commit support (JSON array)
  • Token-based authentication for cross-repo push
  • Job summary with commit details
  • Rich outputs: commit SHA, URL, changed files list

Usage

Basic Usage

name: commit-and-push
on:
  push:
    branches: [main]

jobs:
  action:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7

      - name: Create a file
        run: echo "Hello World" >> hello.txt

      - name: Commit and push the file
        uses: maxgfr/github-commit-push-file@main
        with:
          commit_message: 'chore: add hello.txt'

Skip If No Changes

Useful for scheduled workflows where you only want to commit if there are actual changes:

- name: Commit and push (if changes)
  uses: maxgfr/github-commit-push-file@main
  with:
    commit_message: 'chore: update data'
    files: 'data/output.json'
    skip_if_no_changes: 'true'

Template Variables

Use template variables in commit messages, body, PR title, and PR body:

- name: Commit with dynamic message
  uses: maxgfr/github-commit-push-file@main
  with:
    commit_message: 'build: deploy {{sha:short}} to {{branch}} on {{date}}'
    commit_body: 'Triggered by {{actor}} in run #{{run_number}}'

Available variables:

Variable Description Example
{{date}} Current date (YYYY-MM-DD) 2026-03-31
{{datetime}} Current ISO datetime 2026-03-31T14:30:00.000Z
{{sha}} Current HEAD SHA abc123def456...
{{sha:short}} Short HEAD SHA (7 chars) abc123d
{{branch}} Target branch name main
{{run_id}} GitHub Actions run ID 12345678
{{run_number}} GitHub Actions run number 42
{{actor}} GitHub actor (user/bot) octocat
{{repository}} Repository (owner/name) maxgfr/my-repo

Working Directory (Monorepo)

- name: Commit in subdirectory
  uses: maxgfr/github-commit-push-file@main
  with:
    commit_message: 'chore: update package'
    work_dir: 'packages/my-package'

Commit Body

- name: Commit with body
  uses: maxgfr/github-commit-push-file@main
  with:
    commit_message: 'feat: add new feature'
    commit_body: |
      This commit adds the new feature X.

      Closes #123

Exclude Files

Stage all files but exclude sensitive ones:

- name: Commit all except secrets
  uses: maxgfr/github-commit-push-file@main
  with:
    commit_message: 'chore: update config'
    exclude_files: '*.env .secrets credentials.json'

File List From File

Read the list of files to stage from a file generated by a previous step:

- name: Generate file list
  run: |
    echo "src/generated.ts" > files-to-commit.txt
    echo "src/types.ts" >> files-to-commit.txt

- name: Commit listed files
  uses: maxgfr/github-commit-push-file@main
  with:
    commit_message: 'chore: update generated files'
    pathspec_from_file: 'files-to-commit.txt'

Create a Branch

Push to a new branch that doesn't exist yet:

- name: Commit to new branch
  uses: maxgfr/github-commit-push-file@main
  with:
    commit_message: 'feat: new feature'
    branch: 'feature/my-feature'
    create_branch: 'true'

Amend Previous Commit

- name: Amend last commit
  uses: maxgfr/github-commit-push-file@main
  with:
    commit_message: 'chore: updated message'
    amend: 'true'
    force_push: 'true'

Create Tags

- name: Commit and tag
  uses: maxgfr/github-commit-push-file@main
  with:
    commit_message: 'release: v1.0.0'
    tag: 'v1.0.0'
    tag_message: 'Release version 1.0.0'

Custom Commit Timestamp

- name: Commit with specific date
  uses: maxgfr/github-commit-push-file@main
  with:
    commit_message: 'chore: backfill data'
    commit_timestamp: '2024-01-01T00:00:00Z'

Push Retry on Conflict

When force_push is disabled and the remote has diverged, automatically pull with rebase and retry:

- name: Commit with retry
  uses: maxgfr/github-commit-push-file@main
  with:
    commit_message: 'chore: update shared file'
    force_push: