我已经在amazon ec2实例上克隆了一个git存储库。我要这样做,以便git pull command
在对远程存储库的同一分支进行新提交时,ec2实例上的本地存储库始终自动同步(也许使用)。我该如何实现?
如果希望保持服务器与服务器所在分支上的最新更改保持同步,则可以按照此处的步骤进行操作。当提交或关闭拉取请求时,将进行“ Git拉取”。
将此添加到您的代码库以触发,
// This function serves as the Payload URL for Github's webhook
// https://github.com/reponame/projectname/settings/hooks/
public function post_receive()
{
// copied from 'https://gist.github.com/1809044'
$commands = array(
'hostname',
'echo $PWD',
'whoami',
'git fetch',
'branch=$(git symbolic-ref -q --short HEAD)',
'git reset --hard origin/$branch',
'git pull',
'git status'
);
// Run the commands for output
$output = '';
foreach($commands AS $command){
// Run it
$tmp = shell_exec($command);
// Output
$output .= "<span style=\"color: #6BE234;\">\$</span> <span style=\"color: #729FCF;\">{$command}\n</span>";
$output .= htmlentities(trim($tmp)) . PHP_EOL.'<br/>';
}
print_r($output);
}
在Github.com上访问Webhooks和服务,https://github.com/reponame/projectname/settings/hooks
点击“添加Webhook”
在“有效载荷URL”中,指定要在其上启用自动“ git pull”的服务器的URL,例如,
“ https://yourserver.com/github/post_receive ”。我们需要确保网址为https(安全),否则我们将获得302
或者,单击“禁用SSL验证”
对于“您想触发哪个网络挂钩事件?”,选择“让我选择单个事件”。然后选择“请求”和“推送”
点击“添加webhook”
在“最近的交货”中,确认您得到的响应正确,并且为绿色。
Webhook Post请求会在您的服务器上触发以下命令,
在Apache服务器上设置www数据组权限
sudo apt-get install members
members www-data
adduser username www-data
chown www-data:www-data -R username
cp -R /home/username/.ssh /var/www/.ssh
chown www-data:www-data -R /var/www/.ssh
ls -la /var/www/.ssh
sudo chmod g+w .git -R
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句