/php-github-sync

Simplest PHP script (and instructions) for using git to keep in sync with a git repository.

Primary LanguagePHPMIT LicenseMIT

github-sync

Simple PHP script (and instructions) for using git to keep a web project in sync with a Github repository.

It uses git reset and git pull to to force the tracked files on your server to match the ones in the Github repository:

  • It will only reset files that are tracked through Git.
  • It won't change any other files.
  • Local changes in the tracked files will be undone.

Git must be installed on the server.

You can use one sync script for multiple projects and branches, each in their own directory.

For your safety, only use this script for actions that are non destructive and which could be triggered at anytime by anybody from anywhere in the internet.

Installing

  • Add this script to your website (as an example as sync/index.php).
  • Create a config.php based on config-demo.php.

Setup the webhook on Github

  • In the settings, add a webhook targeting this PHP script.
    • url: path to this script (http://your-server.org/sync/)
      (the final / might matter).
    • Select json as the content type.
    • Define a secret (you will put the same in your config.php file.
  • Each time your repository gets pushed, a git reset it will be triggered on your server.

Todo

  • support other commands (mostly a call to shell scripts) after having synced.

Resources