I will be working on two projects (say project A and project B) that are based on the same boilerplate PHP theme. Oftentimes I’ll have to make the same change to both, even though the code will be slightly different in each project.
For example, suppose I’ve added function_1() and function_2() to A/index.php, but I want to only add function_2 to B/index.php. Or the same for removing content or making alterations.
For major changes it would be inefficient to yank-paste back and forth between files.
I’m assuming this is the sort of stuff a more advanced git tutorial might help with? — or maybe there’s a tool made especially for this purpose? — Where can I find documentation on dealing with this sort of thing.
What you really should do is create a “template” branch/repo which contains the common code. You then branch the customized repos from that template branch. When you make changes to the template, you can merge them into the customized repos.
Now, since you already have the other repos present, you have to fudge the changes in. Basically create a template repo with the non-customized changes which all repos have been manually updated for. Then add the customized repos as remotes to this template repo
git remote add customized1 URLand checkout the appropriate branchgit checkout -t -b customized1-master customized1/masterThen do a “fake” merge from the template’s master into each customized master:
You of course may check to see what it did before doing the push.
At this point you have injected your template branch as a relevant ancestor to your customized repos/branches. You can then make a change to your template branch (called master in my example in this new repo) and after committing, do a real merge:
You almost certainly want to inspect what happened before you push this time. Now, changes to the template can be easily shared with all customized repos. Also if you need a new customized repo, you can branch it from the template branch.