Need help with add-and-commit?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

EndBug
320 Stars 48 Forks MIT License 471 Commits 2 Opened issues

Description

Add & commit files from a path directly from GitHub Actions

Services available

!
?

Need anything else?

Contributors list

# 174,291
google-...
google-...
Google
Python
265 commits
# 314,983
forge
Gradle
PHP
HTML
7 commits
# 15,826
PHP
WordPre...
php-cur...
React
3 commits
# 60,363
SQL
Git
registe...
signup
2 commits
# 29,554
Firefox
qr-gene...
reactjs
pastebi...
2 commits
# 156,738
HTML
CSS
Shell
ncov
1 commit
# 22,742
github-...
MATLAB
PHP
ad-bloc...
1 commit
# 1,044
C#
Jenkins
css-fra...
schema-...
1 commit
# 58,916
Xcode
Ruby
Objecti...
mac
1 commit

Add & Commit

Public workflows that use this action. All Contributors

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....

This is heavily inspired by git-auto-commit-action (by Stefan Zweifel): that action automatically detects changed files and commits them. While this is useful for most situations, this doesn't commit untracked files and can sometimes commit unintended changes (such as

package-lock.json
or similar, that may have happened during previous steps).
This action lets you choose the path that you want to use when adding & committing changes so that it works as you would normally do using
git
on your machine.

Inputs

Add a step like this to your workflow:

- uses: EndBug/[email protected] # You can change this to use a specific version.
  with:
    # The arguments for the `git add` command (see the paragraph below for more info)
    # Default: '.'
    add: 'src'

# The name of the user that will be displayed as the author of the commit.
# Default: depends on the default_author input
author_name: Author Name

# The email of the user that will be displayed as the author of the commit.
# Default: depends on the default_author input
author_email: [email protected]

# The name of the branch to use, if different from the one that triggered the workflow.
# Default: the branch that triggered the run
branch: some-branch

# The name of the custom committer you want to use, if different from the author of the commit.
# Default: the name of the author (set with either author_name or default_author)
committer_name: Committer Name

# The email of the custom committer you want to use, if different from the author of the commit.
# Default: the email of the author (set with either author_email or default_author)
committer_email: [email protected]

# The local path to the directory where your repository is located. You should use actions/checkout first to set it up.
# Default: '.'
cwd: './path/to/the/repo'

# Determines the way the action fills missing author name and email. Three options are available:
# - github_actor -&gt; UserName <username>
# - user_info -&gt; Your Display Name <your-actual>
# - github_actions -&gt; github-actions <email associated with the github logo>
# Default: github_actor
default_author: github_actor

# The message for the commit.
# Default: 'Commit from GitHub Actions (name of the workflow)'
message: 'Your commit message'

# The way the action should handle pathspec errors from the add and remove commands. Three options are available:
# - ignore -&gt; errors will be logged but the step won't fail
# - exitImmediately -&gt; the action will stop right away, and the step will fail
# - exitAtEnd -&gt; the action will go on, every pathspec error will be logged at the end, the step will fail.
# Default: ignore
pathspec_error_handling: ignore

# Arguments for the git pull command. Use NO-PULL to avoid the action pulling at all.
# Default: '--no-rebase'
pull: 'NO-PULL or --rebase --autostash ...'

# Whether to push the commit and, if any, its tags to the repo. It can also be used to set the git push arguments (see the paragraph below for more info)
# Default: true
push: false

# The arguments for the `git rm` command (see the paragraph below for more info)
# Default: ''
remove: './dir/old_file.js'

# Whether to use the --signoff option on `git commit` (only boolean values accepted*)
# Default: false
signoff: true

# Arguments for the git tag command (the tag name always needs to be the first word not preceded by an hyphen)
# Default: ''
tag: 'v1.0.0 --force'

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 string that contain a lot of nested quotes may be parsed incorrectly, and that specific ways of declaring arguments may not be supported by this 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 aprsed correctly you'll see an array where every string is an option or value.

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.
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.

Deleting files

You can delete files with the

remove
option: that runs a
git rm
command that will stage the files in the given path for removal. As with the
add
argument, you can use every option
git rm
allows (e.g. add
--force
to ignore
.gitignore
rules).
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.
You can also use JSON or YAML arrays (e.g.
'["first", "second"]'
,
"['first', 'second']"
) to make the action run multiple
git rm
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.

Pushing

By default the action runs the following command:

git push origin ${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 branch of your repo: you'll need to set the

push
input to, for example,
origin yourBranch --force
.

Tagging

You can use the

tag
option to enter the arguments for a
git add
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).

Tokens

When pushing, the action uses the token that the local git repository has been configured with: that means that if you want to change it you'll need to do it in the steps that run before this action. For example: if you set up your repo with

actions/checkout
then you have to add the token there.
Changing the token with which the repo is configured can be useful if you want to run CI checks on the commit pushed by this action; anyway, it has to be set up outside of this action.

The action automatically gets the GitHub token from a

github_token
input: this input should not be modified by the user, since it doesn't affect the commits as it's only used to access the GitHub API to get user info, in case they selected that option for the commit author.

About
actions/checkout

The token you use when setting up the repo with this action will determine what token

add-and-commit
will use.
Some users reported that they were getting an error:
> fatal: could not read Username for 'https://github.com': No such device or address

If you're getting this error and you're using

actions/[email protected]
, try upgrading to
actions/[email protected]
. If you're still having problems after upgrading, feel free to open an issue. Issue ref: #146

Outputs

The action provides these outputs:

  • committed
    : whether the action has created a commit (
    'true'
    or
    'false'
    )
  • commit_sha
    : the short 7-digit 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'
    )

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

Examples

If you don't want to use your GitHub username for the CI commits, you can use the

default_author
option to make it appear as if it was made by "github-actions"

on: push
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: EndBug/[email protected]
        with:
          default_author: github_actions

You can also use the

committer_name
and
committer_email
inputs to make it appear as if GitHub Actions is the committer, here are a couple of example steps:

- uses: EndBug/[email protected]
  with:
    message: Show GitHub Actions logo
    committer_name: GitHub Actions
    committer_email: [email protected]

- uses: EndBug/[email protected]
  with:
    message: Show GitHub logo
    committer_name: GitHub Actions
    committer_email: 41898282+github-actions[bot]@users.noreply.github.com

Do you want to lint your JavaScript files, located in the

src
folder, with ESLint, so that fixable changes are done without your intervention? You can use a workflow like this:
name: Lint source code
on: push

jobs: run: name: Lint with ESLint runs-on: ubuntu-latest steps: - name: Checkout repo uses: actions/[email protected]

  - name: Set up Node.js
    uses: actions/[email protected]
    with:
      node-version: 12.x

  - name: Install dependencies
    run: npm install

  - name: Update source code
    run: eslint "src/**" --fix

  - name: Commit changes
    uses: EndBug/[email protected]
    with:
      author_name: Your Name
      author_email: [email protected]
      message: 'Your commit message'
      add: '*.js'

If you need to run the action on a repository that is not located in

$GITHUB_WORKSPACE
, you can use the

cwd
option: the action uses a
cd
normal command, so the path should follow bash standards.
name: Use a different repository directory
on: push

jobs: run: name: Add a text file runs-on: ubuntu-latest

steps:
  # If you need to, you can check out your repo to a different location
  - uses: actions/[email protected]
    with:
      path: './pathToRepo/'

  # You can make whatever type of change to the repo...
  - run: echo "123" &gt; ./pathToRepo/file.txt

  # ...and then use the action as you would normally do, but providing the path to the repo
  - uses: EndBug/[email protected]
    with:
      message: 'Add the very useful text file'
      add: '*.txt --force'
      cwd: './pathToRepo/'

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Federico Grandi

💻 📖

Tor Egil Jacobsen

💻

Ivan Yelizariev

🤔

jhhughes

🐛

Дмитрий Океаний

🤔

Brahma Dev

🐛

Felix Rojo Lapalma

🐛

Robin Wijnant

🐛 💻

Onilton Maciel

🤔

Josh Soref

📖

ToMe25

💻 🤔

JonasJacobsUserspace

🐛

pvogt09

💻

Connor Clark

🤔

Benedek Kozma

🤔 💻

Dustin Brown

🐛

Chris McIntosh

🐛

Kevin Saliou

🤔

Joachim Jablon

🤔

Tim Schwenke

🤔

Possible Triangle

🤔

Dominik Schilling

🤔 📖 💻

rugk

📖

Caleb Cushing

🐛

Eero Ruohola

🐛 🤔

Vincent Chu

🐛

Matt H

📖 🤔

danielwerg

📖

Oliver Kopp

🤔

Glenn Ko

🤔

This project follows the all-contributors specification. Contributions of any kind welcome!

License

This action is distributed under the MIT license, check the license for more info.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.