Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
A

add-and-commit

> DevOps
Open source

:octocat: Automatically commit changes made in your workflow run directly to your repo

1.3K stars0 likes2 views
WebsiteGitHub

About

:octocat: Automatically commit changes made in your workflow run directly to your repo

Add & Commit

You can use this GitHub Action to commit changes made in your workflow run directly to your repo: for example, you use it to lint your code, update documentation, commit updated builds, etc...

Table of contents

  • Inputs
  • Outputs
  • FAQs
  • Examples
  • Contributors
  • Articles

Inputs

Add a step like this to your workflow:

…

Git arguments

Multiple options let you provide the git arguments that you want the action to use. It's important to note that these arguments are not actually used with a CLI command, but they are parsed by a package called string-argv, and then used with simple-git.
What does this mean for you? It means that strings that contain a lot of nested quotes may be parsed incorrectly, and that specific ways of declaring arguments may not be supported by these libraries. If you're having issues with your argument strings you can check whether they're being parsed correctly either by enabling debug logging for your workflow runs or by testing it directly with string-argv (RunKit demo): if each argument and option is parsed correctly you'll see an array where every string is an option or value.

Remote-helper overrides (--upload-pack, --receive-pack, --exec, and abbreviations of those) are rejected on every token, including values after -u / -m: they can make git run an arbitrary Git transport program during fetch/pull/push.
Remote-helper URL forms (ext::… and other scheme:: tokens) are rejected for the same reason.
Git child processes are also limited to the https, http, ssh, file, and git transports (GIT_ALLOW_PROTOCOL) unless you set allow_unsafe_git_protocols to true (only for trusted custom remotes/helpers).
Message-from-file flags (-F, --file, abbreviations such as --fi, and short-option clusters that include F such as -aF) are rejected: they can embed arbitrary runner filesystem contents into a tag or commit message and, with a push, into the repository history.
Pathspec-from-file flags (--pathspec-from-file, --pathspec-file-nul, and abbreviations such as --pathspec-fr / --pathspec-fi) are rejected on add, remove, and commit: they can read an arbitrary runner file and leak its contents into the action log.
Unmatched ' / " quotes are also rejected: string-argv can otherwise split on an odd quote and turn part of a value into extra flags (for example a branch name like fix'--force becoming fix plus --force).
A quoted segment is accepted only when its closing quote is followed by whitespace or the end of the input. That is a conservative argument-boundary check, not a claim that every rejected form would become extra argv words: 'main'--force is rejected (and would split into main plus --force), and so is a'b'c (which string-argv would keep as one token). --message='hello' is allowed because the closer is at the end of the word. Put a space after a wrapping closer (origin 'main' --force) or omit the quotes.

[!WARNING] Do not interpolate untrusted data (for example values from github.event.*, github.head_ref, or repository content that contributors can edit) into fetch, pull, push, tag, tag_push, or commit without sanitizing them first. When the branch name is dynamic, prefer the default push: true with new_branch instead of embedding the ref in a custom push string.

Allow unsafe git protocols

Set allow_unsafe_git_protocols: true only if you need a custom remote helper or a transport outside the default allowlist (https, http, ssh, file, git). This disables both the GIT_ALLOW_PROTOCOL restriction and the rejection of scheme:: tokens in git argument inputs. It does not re-enable blocked options such as --upload-pack, -F/--file, or --pathspec-from-file/--pathspec-file-nul. Treat this like a break-glass setting: only enable it with fully trusted, non-interpolated argument strings.

Adding files

The action adds files using a regular git add command, so you can put every kind of argument in the add option. For example, if you want to force-add a file: ./path/to/file.txt --force.
The script will not stop if one of the git commands doesn't match any file. E.g.: if your command shows a "fatal: pathspec 'yourFile' did not match any files" error the action will go on, unless specified otherwise with pathspec_error_handling.
You can also use JSON or YAML arrays (e.g. '["first", "second"]', "['first', 'second']") to make the action run multiple git add commands: the action will log how your input has been parsed. Please mind that your input still needs to be a string because of how GitHub Actions works with inputs: just write your array inside the string, the action will parse it later.

The action refuses to commit if git add would introduce a new gitlink (mode 160000) — for example when a directory contains its own nested .git folder. Git would otherwise record that path as an embedded repository reference rather than its files, often with only a silent warning. Remove the nested .git directory, or unstage the path with git rm --cached -- , before committing. Updates to existing submodules (already tracked as gitlinks) are still allowed.

Deleting files

The remove option can be used if a predetermined list of files needs to be removed. It runs the git rm command, so you can pass every kind of argument with it. As if with the add input, you can also use JSON or YAML arrays to make the action run multiple git rm commands.

If you want deleted files to be auto-detected and committed, you can use the --no-ignore-removal/-A git arguments.

Pushing

By default the action runs the following command: git push origin ${new_branch input} --set-upstream. You can use the push input to modify this behavior, here's what you can set it to:

  • true: this is the default value, it will behave as usual.
  • false: this prevents the action from pushing at all, no git push command is run.
  • any other string:
    The action will use your string as the arguments for the git push command. Please note that nothing is used other than your arguments, and the command will result in git push ${push input} (no remote, no branch, no --set-upstream, you have to include them yourself).

One way to use this is if you want to force push to a trusted/static branch name in your repo: set the push input to, for example, origin yourBranch --force. Do not build that string from untrusted refs such as github.head_ref.

If multiple jobs may push to the same branch (for example a matrix), set push_attempts to try the push more than once. When pull is set (true for a default git pull, or a string such as --rebase --autostash), each failed attempt re-runs that pull before pushing again, so a commit that lost a race can catch up to the remote tip. Without pull, retries only re-run push. The default is 1 (no retries). A typical concurrent setup looks like:

yaml
with:
  pull: '--rebase --autostash'
  push_attempts: 3

Creating a new branch

If you want the action to commit in a new branch, you can use the new_branch input. This must be a valid git branch name (not raw git arguments): it cannot be empty, start with -, contain whitespace/control characters, or fail git check-ref-format --branch (for example feature..name, name@{x}, name~1, or a name ending with .).

Please note that if the branch exists, the action will still try push to it, but it's possible that the push will be rejected by the remote as non-straightforward.

If that's the case, you need to make sure that the branch you want to commit to is already checked out before you run the action.
If you're really sure that you want to commit to that branch, you can also force-push by setting the push input to something like origin yourBranchName --set-upstream --force (use a trusted/static branch name, not an untrusted ref).

If you want to commit files "across different branches", here are two ways to do it:

  1. You can check them out in two different directories, generate your files, move them to your destination and then run add-and-commit in the destination directory using the cwd input.
  2. You can manually commit those files with git commands as you would on your machine. There are several ways to do this depending on the scenario. One of them if to stash your changes, checkout the destination branch, and popping the stash. You can then use the add-and-commit action as usual. Please note that this is just an example and may not work for you, since your use case may be different.

Tagging

You can use the tag option to enter the arguments for a git tag command. In order for the action to isolate the tag name from the rest of the arguments, it should be the first word not preceded by an hyphen (e.g. -a tag-name -m "some other stuff" is ok).
You can also change the arguments of the push command for tags: every argument in the tag_push input will be appended to the git push --tags command.
For more info on how git arguments are parsed, see the "Git arguments" section.

Dry run

Set dry_run: true if you want the action to validate your inputs and log what it would do, without changing the repository. Staging uses git add --dry-run / git rm --dry-run; commit, tag, push, pull, fetch, checkout, and git identity config are only reported in the logs.
Outputs stay at their defaults (committed/pushed/tagged/tag_pushed are 'false', and commit SHAs are empty) because nothing was actually created.

Outputs

The action provides these outputs:

  • committed: whether the action has created a commit ('true' or 'false')
  • commit_long_sha: the full SHA of the commit that has just been created
  • commit_sha: the short 7-character SHA of the commit that has just been created
  • pushed: whether the action has pushed to the remote ('true' or 'false')
  • tagged: whether the action has created a tag ('true' or 'false')
  • tag_pushed: whether the action has pushed a tag ('true' or 'false')

For more info on how to use outputs, see "Context and expression syntax".

FAQs

Working with PRs

By default, when you use actions/checkout on a PR, it will checkout the head commit in a detached head state. If you want to make some changes, you have to checkout the branch the PR is coming from in the head repo.
You can set it up like this:

yaml
- uses: actions/checkout@v4
  with:
    repository: ${{ github.event.pull_request.head.repo.full_name }}
    ref: ${{ github.event.pull_request.head.ref }}

You can find the full docs for payloads of pull_request events here.

If you're planning on running this only on "internal" PRs (where head and base are in the same repo) then you can omit the repository input.
If you're planning to use this with PRs coming from other forks, please keep in mind that you might not have write access to those repos. You can try setting up the repo with your PAT, as explained in the "About tokens" paragraph of this section.

Keep in mind that this "custom checkout" is meant only for PRs: if your workflow runs on multiple events (like push or workflow_dispatch), you could tr

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

TypeScriptactionsautomationcicollaborate

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
CategoryDevOps
PricingOpen source

> Related tools

D
Docker
容器化平台,标准化应用交付
G
GitHub Actions
GitHub 原生 CI/CD 工作流
N
Nginx
高性能 Web 服务器与反向代理