Daily git commit emails

Git can send an email for each git push into the repository
using the post-receive hook. I wanted to have daily messages, as
opposed to one for each commit. The following script does that:

#!/bin/bash

# duration of log (default: daily) as offset since now
RELDATE="24 hours ago"

# email recipient
EMAIL=a@b

# bare repository home
GITROOT=/opt/git/nexus

# branch
BRANCH=refs/heads/master

cd $GITROOT/hooks

# the latest commit
NEWREV=`git rev-list -n 1 HEAD`

# the latest commit not to report 
OLDREV=`git rev-list -n 1 --date=relative --until="$RELDATE" HEAD`

# only send an email if there are commits
if [[ $NEWREV == $OLDREV ]]
then
 exit 0
fi

/usr/share/doc/git-core/contrib/hooks/post-receive-email \
$BRANCH $OLDREV $NEWREV | /usr/sbin/sendmail $EMAIL


Change the GITROOT variable to point to the root of your repository and create a daily cron job:

crontab -e


For instance

12 2 * * * /usr/sbin/git-dailylog.sh


Some assumptions:
  • This might only work for bare repositories.
  • sendmail in this example is taken from ssmtp, real sendmail may differ.
  • verify the location of the post-receive-email script on your system


If you know of a simpler method, let me know.

Comments