title: Automate Deployments with Git, Bitbucket and PHP
body: <p>I'm in the process of trying to set up automatic deployments when I make a git push to my bitbucket repository.  I have a php deploy script that I leveraged from <a href="http://brandonsummers.name/blog/2012/02/10/using-bitbucket-for-automated-deployments/" rel="nofollow">this blog</a> but when the script runs it is logging that it's only updating from a previous commit. </p>
  
  <p>Here is an example.  Let say I log into my server and type git pull.  The server will update with the latest changes and lets say the hash for that commit was 001.  However if I make several commits lets call them 002, 003, and 004 my script should run every time assuming I pushed those changes to bitbucket after every commit.  The script runs but every time it will keep the changes from 001.  Only when I log into my server and type git pull, will the server update to 004. Do you know what would cause this? </p>
  
  <pre><code>// Make sure we're in the right directory
  exec('cd '.$this-&gt;_directory, $output);
  $this-&gt;log('Changing working directory... '.implode(' ', $output));
  
  // Discard any changes to tracked files since our last deploy
  exec('git reset --hard HEAD', $output);
  $this-&gt;log('Reseting repository... '.implode(' ', $output));
  
  // Update the local repository
  exec('git pull '.$this-&gt;_remote.' '.$this-&gt;_branch, $output);
  $this-&gt;log('Pulling in changes... '.implode(' ', $output));
  
  // Secure the .git directory
  exec('chmod -R og-rx .git');
  $this-&gt;log('Securing .git directory... ');
  
  if (is_callable($this-&gt;post_deploy))
  {
   call_user_func($this-&gt;post_deploy, $this-&gt;_data);
  }
  
  $this-&gt;log('Deployment successful.');
  </code></pre>