Rss Feed Tweeter button Facebook button Technorati button Reddit button Linkedin button Webonews button Delicious button Digg button Flickr button Stumbleupon button Newsvine button

A Waage Blog

Ruby, Rails, Life

Adding Git Email Notifications via Post-receive hook

with 8 comments

This was done on Fedora 10 in my case, but should be similar for all distributions. This is set up on a shared ‘central’ repository, where changes are pushed to. That’s why it’s done using the post-receive hook (the repository receives changes).

Step 1: Copy (or symlink) the post-receive script, or download it here. The script must be in the ‘hooks’ directory like this:
$GIT_DIR/hooks/post-receive

I’ve read that on Debian systems, for example, the hook is stored in /usr/share/doc/git-core/contrib/hooks/post-receive-email but i had no luck finding it here on my system.

Make sure it is named “post-receive” so that Git recognizes it.

Step 2: Make sure that the script is executable:

chmod a+x $GIT_DIR/hooks/post-receive

Step 3: Edit the first line of $GIT_DIR/description to be your repository name. This will be in the subject of the email.

Step 4: Edit $GIT_DIR/config with some email settings such as recipient / sender email and subject-line prefix. Here’s some basic settings (read the script for all possible settings).

[hooks]
mailinglist = "receiver1@receivers.com, receiver2@receivers.com"
envelopesender = sender@senders.com
emailprefix = "[GIT] "

Note: you can also set these by using git-config:

git-config hooks.mailinglist "receiver1@receivers.com, receiver2@receivers.com"
git-config hooks.envelopesender sender@senders.com
git-config hooks.emailprefix "[GIT] "

That’s it ! Try doing a git-push to your shared repository, and see if you get email notifications. If not, try tailing your mail log to see what’s wrong (/var/log/maillog).

Written by Andrew Waage

May 19th, 2010 at 1:39 pm

Posted in Git and SVN

Tagged with , , , ,

8 Responses to 'Adding Git Email Notifications via Post-receive hook'

Subscribe to comments with RSS or TrackBack to 'Adding Git Email Notifications via Post-receive hook'.

  1. Thanks man!

    Peter Jankuliak

    18 Oct 11 at 2:29 pm

  2. Would this work as a post-merge.
    Reason would be to email others there’s been a pull to the live stage. thanks for the howto

    Greg K

    14 Apr 12 at 6:25 am

  3. As a post-merge hook: (didn’t work out)
    2 files changed, 2 insertions(+), 1 deletions(-)
    create mode 100644 README.md
    .git/hooks/post-merge: line 232: syntax error near unexpected token `&’
    .git/hooks/post-merge: line 232: ` cat <<-EOF’

    Greg K

    14 Apr 12 at 6:26 am

  4. Thanks so much! This setup was confusing me for the longest time.

    Lou

    7 Aug 12 at 1:51 pm

  5. FYI, on Debian systems, the post-receive-email script is /usr/share/doc/git/contrib/hooks/post-receive-email and provided by the git package.

    In the default debian post-receive.sample file, the path to the script is incorrect, and needs to be changed to the path above.

    Vittal

    21 Feb 13 at 3:55 am

  6. Thanks, i can push my files to the server but i can’t send email notifications.i already check the mail.log but there is nothing inside that one.how can i check the logs

    sunanda

    27 Jun 13 at 12:56 am

  7. worked perfectly with no efforts at all. thank you so much!

    kishore

    3 Jul 13 at 6:07 am

  8. Hi,

    I want to use my own SMTP server and not the mailx programe. Where to add my smtp server details in this process.

    Regards,

    Tariq

    21 Nov 14 at 4:01 am

Leave a Reply