Git Throws Error If Nothing To Commit. How To Surpress?


I have a CI/CD pipeline in GitHub Actions that runs and one of the steps is to commit to another repository. What it does is that it clones to external repository, moves files into it, and then commits it back to the external repository.

The thing is, there is no grantee that there will be a new file to commit.

When that happens, the repository fails because Git throws an error as shown

enter image description here

How can I get around that?


You could use the git status --porcelain command (reference 1 + reference 2) to check if some changes occurred.

It could look like this using bash:

        if [[ `git status --porcelain` ]]; then
          echo "OK: Changes detected."
          echo "WARNING: No changes were detected."
      shell: bash

Obs: I’m using it in a action to git commit push changes.

Answered By – GuiFalourd

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published