Skip to content

Git commands as if condition of a step in workflow #27148

Discussion options

You must be logged in to vote

Sorry, I put true and false the wrong way around in my example. According to the documentation git diff --exit-code will return 0 if there are no changes, and in Bash 0 means true, contrary to C… 😅

So the check should be:

- name: check for changes
  run: |
    if git diff --exit-code; then
      echo "::set-env name=changes_exist::false"
    else
      echo "::set-env name=changes_exist::true"
    fi

I hope this works, at least the mixup explains why you got “nothing to commit” in the first screenshot.

Replies: 4 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants