git Commit Email Notification

I couldn’t really find anything that could get me up and running really quickly with git commit emails. In this blog post we provide a git post-receive-email example.  In our case, our server is CentOS.

  1. modify the “description” file on the server in the root of the git repo, so that your project can have a name, and the email subject lines will have that name.
  2. setup the post receive configuration in /etc/gitconfig
  3. In the hooks directory on the server, copy the post-receive.sample to post-receive, and uncomment the post-receive-email script

If in the root of the git repo, issue the following commands to do the above.

 echo "Project Name" > description
cat > hooks/post-receive <<END
#!/bin/sh
. /usr/share/git-core/contrib/hooks/post-receive-email
END
git config hooks.mailinglist list@example.com
# show the diff of the commit
git config hooks.showrev "git show -C %s; echo"

Note that the git config command above will change the “config” file in that repo to have a proper email destination.