GitHub Action
Add, commit, and push
✨ Automagically git add
, git commit
, and git push
on:
push:
branches: "main"
jobs:
job:
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npx --yes prettier --write .
- uses: actions4git/add-commit-push@v1 |
➕ Adds all files by default
👨 Uses github.actor
as the default author
🤖 Uses @github-actions[bot] as the default committer
🔼 Pushes changes to the current branch or tag
🏷️ Will automatically use --force
if it's a Git tag
A convenience wrapper with sensible defaults so that you don't have to do
git add
, git commit
, and git push
manually all the time. 😉
🚀 Here's what you want:
on:
push:
branches: "main"
jobs:
job:
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npx --yes prettier --write .
- uses: actions4git/add-commit-push@v1
🔒 Make sure you have the permissions
set to contents: write
! We need to be
able to edit the repository contents to push things.
You can also use this GitHub Action with tags/releases
on:
release:
types: released
jobs:
job:
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: echo "$TAG" > VERSION.txt
env:
TAG: ${{ github.event.release.tag_name }}
- uses: actions4git/add-commit-push@v1
If you're looking to have more control than the options provided below, it's
best if you tap in to the git
CLI directly. The only tricky bit is setting a
default Git user (it's unset by default). You can either set it manually or use
a premade action like [actions4git/setup-git] to configure the user.name
and
user.email
settings.
- uses: actions/checkout@v4
- uses: actions4git/setup-git@v1
# OR
- run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "$GITHUB_ACTOR_ID+$GITHUB_ACTOR@users.noreply.github.com"
# OR
- run: |
git config user.name 'github-actions[bot]'
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
# Then you can do whatever you want!
- run: git add ...
- run: git rebase ...
- run: git merge ...
- run: git commit ...
- run: git push ...
-
path
: The path to the repository root folder to perform the Git operations in. This defaults to the current working directory (.
). Change this to a subfolder if you are using a different folder other than the defaultgithub.workspace
for your Git repository. -
add-pathspec
: Additional path specifiers to be passed togit add
. These can be files, folders, globs, or even some fancy Git pathspec things such as:!ignoreme.txt
. Check out the CSS-Tricks Git Pathspecs and How to Use Them article for the highlights of Git pathspecs. If this input is not specified,git add --all
will be used instead. Specifying.
has slightly different behavior from--all
. -
add-force
: Whether or not to use the--force
flag when performing thegit add
operation. Use this if you really want to add something but it's in your.gitignore
. This can be useful if you ever need to commit build artifacts to Git that are normally ignored by your.gitignore
. Defaults tofalse
. -
commit-author
: AName Here <emailhere@example.org>
AiO author name & email string. This is a shortcut alternative to the independant 'commit-author-name' andcommit-author-email
options that are also available. This defaults to @github-actions[bot]. You can set this to the special valuegithub-actions
to use the @github-actions[bot] user as the author, or the specialme
value to use the currentgithub.actor
user as the author. Note that this is different from thecommit-committer
. The author of a commit is who wrote the thing and the committer is who committed it to Git. It's recommended to leave this as the default. -
commit-author-name
: The name of the author to associate with the commit. Should be left unspecified ifcommit-author
is specified. -
commit-author-email
: The email address of the author to associate with the commit. Should be left unspecified ifcommit-author
is specified. -
commit-committer
: AName Here <emailhere@example.org>
AiO author name & email string. This input is a shortcut for thecommit-committer-name
andcommit-committer-email
inputs that can also be individually specified. You can set this to the special valuegithub-actions
to use the @github-actions[bot] user as the committer, or the specialme
value to use the currentgithub.actor
user as the committer. If this input is unspecified, the committer defaults to the author. -
commit-committer-name
: The name of the committer to associate with the commit. Should be left unspecified ifcommit-committer
is specified. -
commit-committer-email
: The email address of the committer to associate with the commit. Should be left unspecified ifcommit-committer
is specified. -
commit-message
: The--message
parameter to use for the commit. This can be a multiline string if you want to specify a title and body. The default is 'Automated changes'. -
push-repository
: The first argument togit push [repository] [refspec]
. You can change this to another remote name likeupstream
(as long as you have push rights) or another Git remote entirely likehttps://github.com/octocat/another-repo.git
. The defaultorigin
is probably what you want. -
push-refspec
: A specific branch or tag name to push to. If this is a tag,push-force
will default totrue
unless explicitly set otherwise. Defaults to whatever the current GitHEAD
target is. -
push-force
: Whether or not to use the--force
parameter when doing thegit push
. You may need to specify this if you are rewriting history or editing a tag. Defaults tofalse
if thepush-refspec
is a branch andtrue
if it's a tag.
TODO!
TODO!