Skip to content

Instantly share code, notes, and snippets.

@JamesSwift
Created August 3, 2012 11:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JamesSwift/3246823 to your computer and use it in GitHub Desktop.
Save JamesSwift/3246823 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 "Your explanation here"
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