action-commit-push
GitHub Action that will create a new commit and push it to the repository
1M+
Powerful GitHub Action for automatically committing and pushing changes back to your repository.
--force and --force-with-lease when neededPerfect for automation workflows and integrates seamlessly with devops-infra/action-pull-request.
This action supports three tag levels for flexible versioning:
vX: latest patch of the major version (e.g., v1).vX.Y: latest patch of the minor version (e.g., v1.2).vX.Y.Z: fixed to a specific release (e.g., v1.2.3). - name: Run the Action
uses: devops-infra/[email protected]
with:
github_token: "${{ secrets.GITHUB_TOKEN }}"
add_timestamp: true
amend: false
commit_prefix: "[AUTO]"
commit_message: "Automatic commit"
force: false
force_with_lease: false
no_edit: false
organization_domain: github.com
target_branch: update/version
| 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 unless there are no changes and amend is false. |
| 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. |
Commit and push changes to the currently checked out branch.
name: Run the Action
on:
push
jobs:
change-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v5
- 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/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
commit_message: "Replace foo with bar"
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@v5
- 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/[email protected]
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@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
body: "**Automated pull request**<br><br>Replaced foo with bar"
title: ${{ github.event.commits[0].message }}
When you need to amend the previous commit and force push (useful when adding automatic changes to manual commit).
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@v5
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/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
commit_message: ${{ github.event.inputs.new_commit_message }}
amend: true
force_with_lease: true # Safer force push option
When using amend: true, you have several options for handling the commit message:
Change the commit message: Set commit_message to provide a new message
- uses: devops-infra/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
commit_message: "Fixed typo in documentation"
amend: true
force_with_lease: true
Keep existing message: Set no_edit: true to keep the original commit message
- uses: devops-infra/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
amend: true
no_edit: true
force_with_lease: true
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!
This action provides two force push options for different scenarios:
force_with_lease (Recommended)git push --force-with-leasefetch-depth: 0 in your actions/checkout stepforce (Use with Caution)git push --force⚠️ Important: Never use both options simultaneously. force_with_lease takes precedence if both are set to true.
Run the Action with a specific version tag.
name: Run the Action
on:
push:
branches-ignore: master
jobs:
action-commit-push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: devops-infra/[email protected]
id: Pin patch version
- uses: devops-infra/[email protected]
id: Pin minor version
- uses: devops-infra/action-commit-push@v1
id: Pin major version
Contributions are welcome! See CONTRIBUTING. This project is licensed under the MIT License - see the LICENSE file for details.
This project is licensed under the MIT License - see the LICENSE file for details.
If you have any questions or need help, please:
Content type
Image
Digest
sha256:aba117943…
Size
97.2 MB
Last updated
1 day ago
Requires Docker Desktop 4.37.1 or later.
Pulls:
4,945
Feb 23 to Mar 1