title: Debugging git hooks
body: <p>I created a git hook that would listen for any new push on the master branch on a local repo and would take a pull on the server (where the web app is deployed) whenever it finds one.</p>
  
  <p>I have referenced this <a href="https://www.digitalocean.com/community/tutorials/how-to-use-git-hooks-to-automate-development-and-deployment-tasks" rel="nofollow noreferrer">example</a> to create my hook.</p>
  
  <p>Below is the hook code:</p>
  
  <p>File name &amp; path: <em>.git/hooks/post-receive</em></p>
  
  <pre><code>#!/bin/sh
  
  set -x
  echo "Pulling new commits" &gt;&gt; hook_receive.log
  while read oldrev newrev ref
  do
      if [[ $ref =~ .*/master$ ]];
      then
          echo "Master ref received.  Deploying master branch to Test..."
          unset GIT_DIR
          git pull
      else
          echo "Ref $ref successfully received.  Doing nothing: only the master branch may be deployed on this server."
      fi
  done
  </code></pre>
  
  <p>I have given the file execute permissions:</p>
  
  <pre><code>chmod +x .git/hooks/post-receive
  </code></pre>
  
  <p>I have set the <code>set -x</code> flag for debug mode and also have tried logging to the file <code>hook_receive.log</code> but nothing is being logged.
  I hope I have use the correct hook.</p>