✨ Automagically git add
, git commit
, and git push
on:
pull_request:
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
🤩 Works great for the common use cases!
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"
pull_request:
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.
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
# Then you can do whatever you want as the @github-actions[bot] user!
- run: git add random.txt
- run: git tag --force v1.0.0
- run: git rebase --interactive HEAD~3
- run: git merge --squash feature-branch
- run: git commit --message 'My custom commit message'
- run: git push origin other-branch:main --force
🏷️ Automatic tag updating coming soon! Contributions welcome! ❤️
-
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 <[email protected]>
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 <[email protected]>
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-force
: Whether or not to use the--force
parameter when doing thegit push
. Defaults tofalse
.
-
committed
: Whether or not anything was actually committed to the repository locally. This will betrue
if there were any changes andfalse
if not. -
commit-sha
: The SHA of the commit that was created. Will not be set if nothing was committed. -
pushed
: Whether or not anything was actually pushed to the remote repository. This will betrue
if there were any changes that were pushed andfalse
if not.
How do I test my changes?
The testing setup is a bit complicated. There's a separate actions4git/add-commit-push-test and actions4git/add-commit-push-test-pull-request-fork testing setup that is manually invoked. When you open a Pull Request make sure you request that a person with write access manually runs those tests! They're a bit too complex to run automatically on each push. 🤷♂️