nathangiesbrecht
nathangiesbrecht

Reputation: 940

Combining Multiple Sites into a single Git Repo

Here's my problem. The company I work for started off with a single website, based on osCommerce (well before I came along). Site grew, they started a second by copying the first, and modifying it where necessary. This continued over the years, to where we now have five separate sites, all based on the same code. When we make a change to one site, I currently have to manually copy those changes to all the other sites code, and upload all the changed code to each of the sites.

This is highly inefficient, and is driving me crazy. I know that Git is pretty much designed to solve such problems. At present, I have each site as it's own Git repo, but I'm still forced to copy modifications from one to all the others. I'm also pretty new to Git. I get commits, branches, pulls, etc. but otherwise am pretty green.

Is there anyway that I can combine all of these sites into one single repo, and how would I do so? I also should point out that the files across each site are not necessarily identical. One site is considered a priority, so some changes have been made there in emergencies that weren't rolled out to the other sites, and another one is run in a slightly different fashion than the other 4, so it's code differs slightly in some places. I realize that this will cause conflicts, but I'd like to be able to find all of the conflicts, resolve them so the system works as intended, and have any variations be database/options driven. The boss wants to roll out at least another 2 sites in a couple of months, so at that point I'll be truly losing my mind.

Is what I'm wanting even possible? Will it require me going through each and every file to resolve conflicts? Any help is much appreciated!

Upvotes: 2

Views: 425

Answers (1)

mikerobi
mikerobi

Reputation: 20878

If you want to merge them together, you are going to have to give up the revision history for some of the versions.

  1. Pick one version as a starting point.
  2. Create a clone of that versions repository for every version of your site, including the original.
  3. Delete the contents of each clone, but leave the .git folder intact.
  4. Copy the contents of each version (excluding .git) into the corresponding copy.
  5. Commit

This will leave you with a branch for each version of the site, plus a master branch for common changes. Each branch will now have a common ancestor.

When merging, you have to be careful to avoid clobbering one version with changes from another. To make this easier, all changes that will be shared between sites should be made in the master branch, and then merged in to the various versions. You will still need to be careful when merging, and will likely need to use the git's cherry pick feature to move individual changesets. You will definately need to cherry pick when bringing in changes from any of the non master branches.

You might make things easier if before you start, you refactor your starting branch so it has less site specific code.

Upvotes: 1

Related Questions