Sonntag, 21. April 2013

POST Hook for GIT (Bitbucket.org)

I am recently messing around with GIT on my favorite site: Bitbucket.org.

As I was working on a website using GIT for the version control, I got tired by always pulling the recent changed onto the WebServer.

Just for the record: I am working on a local maschine with a test-environment and pulling all my pushes to the remote WebServer (LAMP).

What you can do is the following:

  • Create a Read-Only access to the Repository with a public-key pair. 
  • Add the public key as a deployment-key to your repository (Repository -> admin -> Deployment-Keys)
  • Pull your Repository to your WebServer via SSH
  • Change ownership of the git-folder (you pulled) to www-data (as this is the apache2 user)
  • Create a public accessable php script that executed a git pull 
  • Place a POST-hook to your php-pull-script on your Server (Repository -> admin -> Services -> POST)
A very basic git pull script could look like this:
<?php
$output = shell_exec('git pull');
echo "<pre>$output</pre>";
?>
 Now you should be done. I hope there is nothing I forgot :)

Questions -> ASK!; Mistakes -> TELL ME! :)

This is just some kind of note for myself. If its helpful for someone else: thumbs up!