Git branch for instances of a website?

I'm working in a couple of websites, both websites needs almost the same code except for some changes in images and css, or settings.

I'm just finished to read the chapter of branchs of Pro Git book and i'm a bit confused, if a branch is not the best solution for this problem, is a fork?

I mean, we have instances A and B of the code, between A and B, the differences are things likes css colors, urls, api keys, but most of the code is the same, so in what way I can deal with this, i need something like code in A and then 'patch' it to get B, but i'm not sure how make a merge that doesn't overrides images...

Anyway, if is a branch or a fork, how can I make a merge for new features in A without lost changes in B?


That's a bit tricky, and I'm afraid there's no single "right" answer. I do agree that maintaining separate branches for A and B is not appropriate use of git.

Your first option is to simply fork one from the other. The downside, of course, is that you now have to maintain two separate code bases. Ugly.

The second option is to fork only the differences (e.g. the images and css directories). This would leave you with 3 git repositories: the code (only one code base to maintain, hooray!), the images/css/etc. for A, and the same for B. The downside with this approach is that it complicates deployment, especially if you have to deploy both code and style changes simultaneously.

Alternatively, you could certainly abuse git to maintain a single repository with both A and B as separate branches. No, it's not ideal, but strictly speaking it would work. However, it's arguably a messier solution to the problem than the first suggestion (forking A and B entirely).

No one but you (and your team) can tell you which is the "right" approach for your situation. I wish you the best of luck, though!


Why not create a "template" branch which has the stuff in common and merge that into the per-website branches? None of the customized stuff should ever appear in the template branch, and ideally the customized stuff would be isolated to special files, though that is not a strict necessity. If you can isolate to the file level, .gitignore the customized files on the template branch for safety.

When you make a change, change it on template and merge to each branch in turn. Each website should get the change applied to template and keep their customized work.