Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 1 down vote accepted

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!

share|improve this answer

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.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .