In my crontab, I have the following line:
48 14 * * * bash /home/erelsgl/git/erel-sites/add-commit-push.bash "from home" 2&>1 >> /home/erelsgl/logs/backup_from_home.log
The script does what its name implies - add, commit and push:
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd $DIR
echo --------------------
date
echo == add ==
/usr/bin/git add -A
echo == commit ==
/usr/bin/git commit -m "$1"
echo == pull ==
/usr/bin/git pull
echo == push ==
/usr/bin/git push
As seen in the log file, the "commit" does nothing while the "pull" works fine:
Fri Oct 23 14:48:01 IDT 2015
== add ==
== commit ==
== pull ==
Already up-to-date.
== push ==
I ran the exact same command, a minute later, from the command line, and got the following log, which means that the commit did happen:
Fri Oct 23 14:49:31 IDT 2015
== add ==
== commit ==
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
== pull ==
Already up-to-date.
== push ==
What is the problem in running commit from a cron job?
NOTE: I also did the same experiment with an actual change in a test file. I found out that, indeed, the commit didn't happen from the crontab (nothing was pushed to upstream) but did happen from the command line.