Here is current the context:
- One developper (myself) working from two different PC's with Visual Studio Code
- One master branch on Github with automatic deployment via a Webhook on the production server
Currently, I launch this each time VS code starts (on both PC's), and it works pretty fine:
git fetch --all
git reset --hard origin/master
git checkout --force origin/master
On the server side, the Webhook calls a script running:
<?php
if ($payload->ref === 'refs/heads/master') {
$commands = array(
'cd /home/www-data/production',
'git fetch --all',
'git reset --hard origin/master',
'git checkout --force origin/master'
);
}
foreach($commands AS $command) {
$tmp = shell_exec($command);
}
I am quite happy with this but now, I would to be able to work on a development server.
My idea was to create a dev branch, and automatically deploy it the same way.
Considering that these are microdevelopments (bug correction) and I don't want to preserve the Dev branch, I've added:
Adding this locally on VS Code on startup:
git reset --hard origin/dev
git branch -D dev
git checkout -b dev origin/dev
Adding this on the server before the foreach loop:
elseif ($payload->ref === 'refs/heads/dev') {
$commands = array(
'cd /home/www-data/development',
'git fetch --all',
'git reset --hard origin/dev',
'git branch -D dev',
'git checkout -b dev origin/dev'
);
}
So the idea was to push the dev branch, check everything is ok, then merge dev on master.
I have made some tests, but Production environment is overwritten each time I publish on the dev branch.
Before digging on that, I'd like to know it this is the better way to proceed, or not.