title: How to let Jenkins git commit only if there are changes?
body: <p>I have a Jenkins job that builds from a github.com repository's master branch with Maven (<code>mvn clean install</code>), then checks for license headers in Java files and missing NOTICE files, and adds them if necessary (<code>mvn license:format notice:generate</code>). Sometimes this will result in changed or added files, sometimes not.</p>
  
  <p>Whenever there have any changes been made (by the license plugin) I want to push the changes to the github repo.</p>
  
  <p>Now I'm having trouble figuring out how best to achieve that. I've added a shell build step after the Maven license plugin where I execute git commands:</p>
  
  <pre><code>git add . # Just in case any NOTICE files have been added
  git commit -m "Added license headers"
  </code></pre>
  
  <p><code>git add .</code> alone works, i.e., doesn't break the build, even if no files have been added. However, <code>git commit</code> breaks the build, if there aren't any changes at all.</p>
  
  <p>I'm not concerned about pushing back to github, as I believe the Git Publisher post-build action can do this for me. Can someone please point me in the right direction for the git commit?</p>