Skip to content

Instantly share code, notes, and snippets.

@LivesInSpb
Forked from JamesSwift/commit_if_changed.sh
Last active January 17, 2018 11:44
Show Gist options
  • Save LivesInSpb/51849fcdde1883980c8d18ac69ba2299 to your computer and use it in GitHub Desktop.
Save LivesInSpb/51849fcdde1883980c8d18ac69ba2299 to your computer and use it in GitHub Desktop.
Sometimes you want to run an automated "git commit -a" (perhaps as a cron job), but you don't want to clog up your history if nothing has changed. I use the following script to run a commit only if changes have been made.
#!/bin/bash
#cd /path/to/your/git/repo/
if [ "$(git status -s)" ] ; then
echo "Changes detected. Commiting."
git add .
git commit -am "Data time and who..."
else
echo "No changes detected. Commit canceled."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment