I'm incorporating git (via Bitbucket/SourceTree/PHPStorm/cPanel) into my web development workflow, and I'm trying to find the most efficient way of managing my development environment. I currently have 3 branches in my git repo, each representing a separate VPS deployment for each release stage in my development workflow (local VPS for individual development, remote development VPS for staging and client previews, and remote production VPS for live websites).
In order for each of these distributions to work, each requires its own custom .cpanel.yml file (for auto deployment), which means I've committed a unique commit to each branch with the custom file, but the rest of the commits are largely exactly the same.
I've tried excluding the .cpanel.yml file from the repo, but cPanel requires this .cpanel.yml file to be checked into the repo in order for auto distribution to run properly. (Initially I thought of including 3 variations on this file and having a git hook unpack the appropriate file but cPanel doesn't recognize any .cpanel.yml files that are not checked into the repo, so this was of no use. I was also unable to find any documentation on overriding the default .cpanel.yml filename)
What is the best methodology to use in this particular case, where I have 3 parallel branches that vary in only a small number of commits? I'm finding that the cherry pick feature in SourceTree is not easy to use on my mac, and I'd prefer a simple method for maintaining common commits across these three branches. I'm also open to a solution that involves consolidating the three unique commits into a single solution (ex. being able to override the default .cpanel.yml filename and commit 3 of these files and point cpanel to the correct one)
Turns out I found a quite elegant solution for this problem that was easy to implement using a simple shell script:
#!/bin/bash
cd /path/to/git/repository/ || exit;
git checkout -f "secondbranch";
git stash; git stash clear;
git merge --no-commit --no-ff "firstbranch";
git reset -- .cpanel.yml;git checkout -- .cpanel.yml;
git reset -- classes/config.php;git checkout -- classes/config.php;
git reset -- deploy.sh;git checkout -- deploy.sh;
bash .git/hooks/pre-commit;
In this example shell script, I have 3 files that are different for each of the 3 branches in my repo: .cpanel.yml
, classes/config.php
, and deploy.sh
. After merging from one branch to the other, I restore the original 3 files for the branch being merged into, and from here I can address any merge conflicts and finally merge successfully.
I've used this script across the dozens of repositories I manage for 9+ months now and it works like a charm!