title: Expected behaviour of if-then-else condition in bash while checking for any changes in git is opposite when written in a github actions workflow
body: <p>If you have a commit statement when there are no changes then it will return an exit code of 1 which will lead to the failure of a GitHub workflow.</p>
  <p>As a workaround, I tried to modify the solution from this <a href="https://stackoverflow.com/questions/8123674/how-to-git-commit-nothing-without-an-error">SO post</a> as well as <a href="https://stackoverflow.com/questions/2657935/checking-for-a-dirty-index-or-untracked-files-with-git/2659808#2659808">this answer</a> which is basically to use -</p>
  <pre><code>git diff-index --quiet HEAD
  </code></pre>
  <p>On my local bash, it works as expected. When I run <code>echo &quot;$?&quot;</code>, the output of 1 or 0 corresponds to what I expect.</p>
  <p>Based off of that and this documentation on <a href="https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable" rel="nofollow noreferrer">setting up environment variable</a> in GitHub workflows, I have the following in my workflow file -</p>
  <pre class="lang-yaml prettyprint-override"><code>- name: Check for changes # This blocks behaviour is just the opposite
    run: |
          if git diff-index --quiet HEAD; then
              echo &quot;changes_exist=true&quot; &gt;&gt; $GITHUB_ENV
          else
              echo &quot;changes_exist=false&quot; &gt;&gt; $GITHUB_ENV
          fi
  
  - name: Debug changes
    run: |
          echo &quot;${{ env.changes_exist }}&quot;
  
  - name: Commit Datasets # It is true whenever there are NO changes and false whenever there are changes, so whenever there are changes it is just skipped due to the &quot;if&quot; condition
    if: env.changes_exist == 'true'
    run: |
          git commit -m &quot;updating datasets&quot;
          git push
  </code></pre>
  <p>However, whenever there are changes to be committed or tracked, the environment variable <strong>changes_exist</strong> is <code>false</code> and vice-versa.</p>
  <p>This is just the opposite of what I am expecting.</p>
  <p>As a workaround till I figure this out I use the following which works perfectly in the worker -</p>
  <pre><code>git diff-index --quiet HEAD || git commit -m &quot;updating datasets&quot;
  </code></pre>
  <p>Any idea why the above works whereas using <code>if - then - else</code> the behavior opposite to what it is supposed to be?</p>