How to get email diffs for GitHub pushes?

Has anyone come up with a good way to get emails when commits are pushed to your GitHub repo — that includes a diff of files changed?

(I know they have an Email Service Hook – but that doesn’t include a diff)

  • What is `git diff --patience` for?
  • Import changes into a git repository from universal diff
  • Also use comma as a word separator in diff
  • Diffing a file against last Mercurial changeset, should it be different?
  • Viewing git filters output when using meld as a diff tool
  • Git get changes between hash A and B to working directory
  • Mega bonus points if the diffs are colorized with inline CSS that’s viewable in Gmail.

  • How to use RUN clone git in dockerfile
  • using git send-mail with google 2-factor authentication
  • Android Studio VCS won't push my new branch to Git
  • Is there negation syntax for git add's filepattern?
  • How to have Git show a file's version history
  • GIT support for branch based user authorization - Best Practices or Tools?
  • 4 Solutions collect form web for “How to get email diffs for GitHub pushes?”

    I’ve written a small WebHook that exactly fills this gap: gitdub. It leverages git-notifier to send one email per commit.

    You are right, the GitHub Email Service hook doesn’t include diff: this is currently a feature request.

    J-16 SDIZ is also right, git-hook-update-notify-email would only be executed locally, not on GitHub side.

    That doesn’t mean said script cannot help: the idea would be to

    • setup a bare repo on your side, cloning the GitHub repo
    • setup a clone of that base repo
    • have a cron job (or Windows task) fetching the GitHub repo every 10 minutes
    • immediately push to the local non-bare repo

    In the local non-bare repo, you can:

    • either use a pre-receive hook (which, as described in the Git book, could be use to compute diff between old-rev and new-rev)
    • or use the aforementioned git-hook-update-notify-email

    In both cases, that mean setup this kind of service locally, which is not ideal.

    May not be the ideal answer for you but if you set up gitolite on your own server you can setup git-commit-notifer, get beautiful colored diff emails, and have unlimited git accounts since you own the server. I do this, and I have never looked back.

    Don’t have a server? You can get a micro Amazon EC2 instance for dirt cheap ($15 a month). We have up to 12 developers and 10 git repos and it all works great on a micro instance.

    The way of doing this is by adding a notification hook script which posts data to your system, with each commit that has been pushed to github.

    E.g.: the payload consists of each commits applied, each having an id:

    {
      :before     => before,
    
      :after      => after,
    
      :ref        => ref,
    
      :commits    => [{
    
        :id        => commit.id, <--- here
    [...]
    

    Second step is to make your script trigger a call to github, using github API, that fetches each commit included in the payload. The response includes a diff for each file, which then you can email to your developers.

    E.g.: http://developer.github.com/v3/repos/commits/#get-a-single-commit

    GET /repos/:owner/:repo/commits/:sha
    

    :sha is the id of the commit you are getting the code for, and the response looks like this:

    [...]
    
     "files": [
    
        {
          "filename": "file1.txt",
          "additions": 10,
          "deletions": 2,
          "changes": 12,
          "status": "modified",
          "raw_url": "https://github.com/octocat/Hello-World/raw/7ca483543807a51b6079e54ac4cc392bc29ae284/file1.txt",
          "blob_url": "https://github.com/octocat/Hello-World/blob/7ca483543807a51b6079e54ac4cc392bc29ae284/file1.txt",
          "patch": "@@ -29,7 +29,7 @@\n....." <---- HERE
        } 
    [...]
    

    Hope this helps. Please ask if you need more details about how to do it.

    Git Baby is a git and github fan, let's start git clone.