Skip to content

Instantly share code, notes, and snippets.

@RadGH
Created October 15, 2015 06:38
Show Gist options
  • Save RadGH/28b8cca5f8ec0b11f5e5 to your computer and use it in GitHub Desktop.
Save RadGH/28b8cca5f8ec0b11f5e5 to your computer and use it in GitHub Desktop.
Git auto pull on commit from Bitbucket with PHP + Webhook
<?php
// Set up a webhook for your Bitbucket repo (or other service) that will visit this script (eg, http://example.org/git-pull.php).
// When you commit, Bitbucket will visit that URL.
// Now the script below runs, which will then pull from the bitbucket repo, grabbing the recently uploaded commit.
// All you have to do is push to Bitbucket!
// NOTE: This script relies on shell_exec and may not work on shared hosts.
$LOCAL_REPO = "/ABSOLUTE/PATH/TO/LOCAL/GIT/REPO/";
$REMOTE_REPO = "https://YOUR_USERNAME:YOUR_PASSWORD@URL_TO_YOUR_REMOTE_GIT_REPO";
shell_exec("cd {$LOCAL_REPO} && git pull {$REMOTE_REPO}");
@tomekit
Copy link

tomekit commented Mar 21, 2018

Your code needs to be writable by the user that runs the webserver. Is that safe?

@RadGH
Copy link
Author

RadGH commented Mar 22, 2018

@tomekit I wouldn't use this in production

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment