碼雲(Gitee)的WebHooks功能,可以在我們每次提交代碼后,向我們設定的地址post一個更新的json信息,這樣我們就可以根據該信息,來自動拉去我們的代碼,實現自動同步功能.
第一步 配置WebHooks

第二步 服務器軟件配置
1、nginx用戶設置成www
2、php用戶設置成www
3、代碼目錄設置成www chown -R www:www 代碼目錄
4、修改代碼目錄下.git文件夾下的config文件里的url地址為 url = https://gitee帳號:gitee密碼@gitee.com/chishenme/gitee倉庫名.git

第三步 服務器腳本配置,在代碼目錄里寫入更新代碼的腳本php
<?php
$requestBody = file_get_contents("php://input");
if (empty($requestBody)) {
die('send fail');
}
$content = json_decode($requestBody, true);
if ($content['ref'] == 'refs/heads/master' && $content['total_commits_count'] > 0 && $content['password'] == 'gitee上設置的webhook密碼') {
exec("cd 代碼目錄 && git pull origin master 2<&1", $output, $return);
$res_log = PHP_EOL . '----------------------------------------------------------------------------------------------------' . PHP_EOL;
$res_log .= $content['user_name'] . ' 在' . date('Y-m-d H:i:s') . '向' . $content['repository']['name'] . '項目的' . $content['ref'] . '分支push了' . $content['total_commits_count'] . '個commit:';
$res_log .= PHP_EOL . "pull start --------" . PHP_EOL;
$res_log .= '$output:' . var_export($output, true) . PHP_EOL . '$return:' . var_export($return, true) . PHP_EOL;
$res_log .= PHP_EOL . "pull end --------" . PHP_EOL;
//$res_log .= var_export($requestBody, true);
file_put_contents(git_webhook.log日志地址, $res_log, FILE_APPEND);//寫入日志到log文件中
}
