PHP Script to pull changes from GIT Repository
Here is a PHP script, that pulls the latest code from Git Repository to your website.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
<?php # Author: Yujin Boby # Web: https://serverok.in/php-script-to-pull-changes-from-git-repository # Email: [email protected] # This script pull latest code from git. $pw = isset($_GET["pw"]) ? $_GET["pw"] : ''; if ($pw != 'YOUR_PASSWORD_HERE') { die("Invalid password"); } $result = exec("git pull origin master 2>&1", $r2); echo "<pre>"; foreach ($r2 as $line) { echo $line . "\n"; } unset($r2); echo "\n\n"; echo "------------------------------------------------------"; echo "\ngit status\n"; echo "------------------------------------------------------"; echo "\n\n"; $result = exec("git status 2>&1", $r2); echo "<pre>"; foreach ($r2 as $line) { echo $line . "\n"; } |
https://gist.github.com/serverok/7efc12fcd75aac21309dbe234d9030f6
Upload the file to your web server as git-pull.php, access it with URL
1 |
https://yourdomain/git-pull.php?pw=YOUR_PASSWORD_HERE |
For this script to work, your web server should work as the user that owns the files. If your webserver runs as www-data, you need to chown the files as www-data.
Example
1 |
chown -R www-data:www-data /path/to/doc/root/ |
See git