title: Git: pre-receive hook to allow only merges and not direct commits into master
body: <p>I have a problem creating a <code>pre-receive</code> hook on a git remote branch, doing what I want.</p>
  
  <p><strong>What's the problem?</strong></p>
  
  <p>Direct commits to the master branch should be not allowed. Only merges into the master branch should be allowed.</p>
  
  <p><strong>Solution</strong></p>
  
  <p>My solution until now is to check, if there are changes in the push from a user, where the master is affected. But the problem is that I can't differentiate if the change is a direct commit or a merge.</p>
  
  <pre><code>#!/bin/sh
  while read oldrefid newrefid refname
  do
  if [ "$refname" = "refs/heads/master" ]; then
          echo $(git merge-base $oldrefid $newrefid)
          echo "---- Direct commit to master branch is not allowed ----"
          echo "Changes only with a merge from another branch"
          exit 1
  fi
  done
  </code></pre>
  
  <p>Has anyone an idea, how to check if the change is a merge?</p>
  
  <p>Thank you!</p>