0

I have a script that runs every so often that will update add, commit and push all the changes in a certain folder with a git repository. (This is because I am a lazy person).

Now this script will do it regardless if there was any actual change. Is there a way with bash to run this script only if changes were made? (Perhaps something with a command similar git status that returns an exit code if changes weren't made).

miraunpajaro
  • 152
  • 2
  • 10
  • [What's an easy way to detect modified files in a Git workspace?](https://stackoverflow.com/a/3899339/2915738) : provides a way to achieve it. You can implement that check in your script. – Asif Kamran Malick Apr 04 '21 at 16:45
  • You can check the result of `git diff` (see the options if you need something in particular), like this `test -n "$(git diff)" && ./your_script.sh`. – Marco Luzzara Apr 04 '21 at 16:50
  • Thanks! @MarcoLuzzara, this is what I wanted! – miraunpajaro Apr 04 '21 at 17:02

0 Answers0