Skip to content

devops-infra/action-commit-push

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

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ GitHub Action for Committing Changes to Repository

πŸ—οΈ Multi-Architecture Support: amd64 and aarch64/arm64

⚠️ Recent Changes in v0.11.0

  • Force behavior updated: force: true now uses git push --force (breaking change)
  • New parameter: force_with_lease for safer force pushing with --force-with-lease
  • Amend improvements: Can now combine amend: true with commit_message to change commit messages
  • Release process: Fully automated releases - zero manual work required!

A powerful GitHub Action for automatically committing and pushing changes back to your repository. Perfect for automation workflows and integrates seamlessly with devops-infra/action-pull-request.

πŸ“¦ Available on

✨ Features

  • πŸ“ Custom commit messages: Add custom prefixes and messages to commits
  • 🌿 Branch management: Create new branches automatically with optional timestamps
  • ⏰ Timestamp support: Add timestamps to branch names for cron-based updates
  • πŸ”„ Integration-ready: Works seamlessly with other DevOps workflows
  • πŸ’ͺ Force push options: Support for --force and --force-with-lease when needed
  • πŸ”€ Pull request integration: Perfect companion for automated PR workflows

πŸ“Š Badge Swag

GitHub repo GitHub code size in bytes GitHub last commit GitHub license
DockerHub Docker version Image size Docker Pulls

πŸ“– API Reference

    - name: Run the Action
      uses: devops-infra/action-commit-push@master
      with:
        github_token: "${{ secrets.GITHUB_TOKEN }}"
        add_timestamp: true
        commit_prefix: "[AUTO]"
        commit_message: "Automatic commit"
        force: false
        force_with_lease: false
        target_branch: update/version

πŸ”§ Input Parameters

Input Variable Required Default Description
github_token Yes "" Personal Access Token for GitHub for pushing the code.
add_timestamp No false Whether to add the timestamp to a new branch name. Uses format %Y-%m-%dT%H-%M-%SZ.
amend No false Whether to make an amendment to the previous commit (--amend). Can be combined with commit_message to change the commit message.
commit_prefix No "" Prefix added to commit message. Combines with commit_message.
commit_message No "" Commit message to set. Combines with commit_prefix. Can be used with amend to change the commit message.
force No false Whether to use force push (--force). Use only when you need to overwrite remote changes. Potentially dangerous.
force_with_lease No false Whether to use force push with lease (--force-with-lease). Safer than force as it checks for remote changes. Set fetch-depth: 0 for actions/checkout.
no_edit No false Whether to not edit commit message when using amend (--no-edit).
organization_domain No github.com GitHub Enterprise domain name.
target_branch No current branch Name of a new branch to push the code into. Creates branch if not existing.

πŸ“€ Output Parameters

Output Description
files_changed List of changed files, as returned by git diff --staged --name-status.
branch_name Name of the branch code was pushed into.

πŸ’» Usage Examples

πŸ“ Basic Example: Commit and Push to Current Branch

Commit and push changes to the currently checked out branch.

name: Push changes
on:
  push
jobs:
  change-and-push:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
      - name: Change something
        run: |
          find . -type f -name "*.md" -print0 | xargs -0 sed -i "s/foo/bar/g"
      - name: Commit and push changes
        uses: devops-infra/action-commit-push@master
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          commit_message: "Replace foo with bar"

πŸ”€ Advanced Example: Commit, Push, and Create Pull Request

Commit and push changes to a new branch and create a pull request using devops-infra/action-pull-request.

name: Push changes and create PR
on:
  push
jobs:
  change-and-push:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
      - name: Change something
        run: |
          find . -type f -name "*.md" -print0 | xargs -0 sed -i "s/foo/bar/g"
      - name: Commit and push changes
        uses: devops-infra/action-commit-push@master
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          commit_prefix: "[AUTO-COMMIT] "
          commit_message: "Replace foo with bar"
      - name: Create pull request
        uses: devops-infra/action-pull-request@master
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          body: "**Automated pull request**<br><br>Replaced foo with bar"
          title: ${{ github.event.commits[0].message }}

πŸ’ͺ Force Push Example: Amending Previous Commit

When you need to amend the previous commit and force push (useful for fixing commit messages or adding forgotten changes).

name: Amend and force push
on:
  workflow_dispatch:
    inputs:
      new_commit_message:
        description: 'New commit message'
        required: true
        default: 'Updated commit message'

jobs:
  amend-commit:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository with full history
        uses: actions/checkout@v4
        with:
          fetch-depth: 0  # Required for force_with_lease
      - name: Make some changes
        run: |
          echo "Additional content" >> README.md
      - name: Amend and force push with lease
        uses: devops-infra/action-commit-push@master
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          commit_message: ${{ github.event.inputs.new_commit_message }}
          amend: true
          force_with_lease: true  # Safer force push option

πŸ“ Amend Options

When using amend: true, you have several options for handling the commit message:

  1. Change the commit message: Set commit_message to provide a new message

    - uses: devops-infra/action-commit-push@master
      with:
        github_token: ${{ secrets.GITHUB_TOKEN }}
        commit_message: "Fixed typo in documentation"
        amend: true
        force_with_lease: true
  2. Keep existing message: Set no_edit: true to keep the original commit message

    - uses: devops-infra/action-commit-push@master
      with:
        github_token: ${{ secrets.GITHUB_TOKEN }}
        amend: true
        no_edit: true
        force_with_lease: true
  3. Default behavior: If neither is set, uses "Files changed:" with file list (when files are modified)

πŸ’‘ Note: Amending works even without file changes - useful for just changing commit messages!

πŸš€ Release Process

This action follows a fully automated release workflow with zero manual intervention:

  • Development branches: Only build and test Docker images (no push to Docker Hub)
  • Test branches (test/*): Build and push Docker images with test- prefix for integration testing
  • Master branch: Only build and test Docker images (no push to Docker Hub)
  • Automatic releases: Triggered by pushes to master - no manual steps required!
  • Weekly builds: Automated test builds run weekly and push test images

πŸ€– Fully Automated Releases

No manual work required! The system automatically:

  1. Detects when a release is needed (new commits to master, excluding docs/dependencies)
  2. Determines version type from merged branch names and commit messages:
    • minor: Merges from feat* branches or "feat:" in commits (v0.10.2 β†’ v0.11.0)
    • patch: All other changes (v0.10.2 β†’ v0.10.3)
  3. Calculates next version using semantic versioning
  4. Creates release branch with version updates using own action
  5. PUSH-OTHER.yml creates the PR automatically
  6. Publishes when PR is merged - Docker images, GitHub release, etc.

🚫 Smart Release Filtering

The system skips releases for:

  • Documentation updates (docs* branches, docs: commits)
  • Dependency updates (dep*, dependabot/* branches, dep: commits)
  • README and other markdown file changes
  • License updates

🎯 Manual Release Trigger (Optional)

You can also trigger releases manually via GitHub Actions UI:

  1. Go to Actions β†’ Auto-Version Release β†’ Run workflow
  2. Choose release type: "minor" or "major" (or leave as "auto" for detection)
  3. Click Run workflow
  4. System handles the rest automatically!

πŸ“ Commit Message Conventions

To help with automatic version detection, use these patterns:

# Patch version (v0.10.2 β†’ v0.10.3) - Most common
git commit -m "fix: resolve issue with force push"
git commit -m "docs: update README"
git commit -m "refactor: improve code structure"

# Minor version (v0.10.2 β†’ v0.11.0) - Feature branches or feat commits
# Create feature branch:
git checkout -b feat/new-functionality
git commit -m "add new amend functionality"
# OR use feat prefix in commits:
git commit -m "feat: add new amend functionality"

🌿 Branch-Based Version Detection

The system prioritizes branch names for version detection:

  • feat/* branches β†’ Minor version bump (v0.10.2 β†’ v0.11.0)

    git checkout -b feat/new-feature
    # When merged to master β†’ minor version bump
  • Other branches β†’ Patch version bump (v0.10.2 β†’ v0.10.3)

    git checkout -b fix/bug-fix
    git checkout -b docs/update-readme
    git checkout -b refactor/cleanup
    # When merged to master β†’ patch version bump

πŸ”’ Major Version Handling

  • Major versions (X in vX.Y.Z) are only incremented manually
  • Use Actions β†’ Auto-Release β†’ Run workflow and select "major"
  • This is reserved for breaking changes or significant API changes

πŸ§ͺ Testing with Test Branches

For testing changes before they reach master:

  1. Create a branch starting with test/ (e.g., test/new-feature)
  2. Push your changes to this branch
  3. The workflow automatically builds and pushes Docker images with test- prefix
  4. Use the test image in other workflows: devopsinfra/action-commit-push:test-latest

This ensures that:

  • βœ… Zero manual release work - everything is automated
  • βœ… Semantic versioning based on branch names and commit messages
  • βœ… Test branches provide safe testing environments
  • βœ… Only reviewed master commits trigger releases
  • βœ… Docker images published only after PR review
  • βœ… No human errors in version management

πŸ“Œ Note: The action references specific versions in action.yml for stability, and the release process keeps these up-to-date automatically.

🎯 Version Usage Options

You can use this action in different ways depending on your needs:

πŸ”„ Latest Version (Recommended)

- uses: devops-infra/action-commit-push@master

Always uses the latest release. Automatically gets new features and fixes.

πŸ“Œ Pinned Version (Stable)

- uses: devops-infra/action-commit-push@v0.11.0

Uses a specific version. More predictable but requires manual updates.

⚠️ Force Push Options

This action provides two force push options for different scenarios:

πŸ›‘οΈ force_with_lease (Recommended)

  • Uses git push --force-with-lease
  • Safer option that checks if someone else has pushed changes to the remote branch
  • Prevents accidentally overwriting other people's work
  • Required: Set fetch-depth: 0 in your actions/checkout step
  • Use case: Amending commits, rebasing, or other history modifications

⚑ force (Use with Caution)

  • Uses git push --force
  • Potentially dangerous as it will overwrite remote changes unconditionally
  • No safety checks - will overwrite any remote changes
  • Use case: Only when you're absolutely certain you want to overwrite remote changes

⚠️ Important: Never use both options simultaneously. force_with_lease takes precedence if both are set to true.

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ”— Related Actions

πŸ’¬ Support

If you have any questions or need help, please:

  • πŸ“ Create an issue
  • πŸ’¬ Start a discussion
  • 🌟 Star this repository if you find it useful!