Alexander Lomia Alexander Lomia - 1 year ago 81
Git Question

How to extract "generic" code from "client-specific" code from a git repo?

I developed an admin panel, which was designed for a specific client. Now, the project requirements demand, that non-client-specific code should be extracted as a separate git branch to serve as a basis for the new client-specific variations of the project.


My goal, as I already mentioned, is to:

  1. Extract the client specific code from my existing project as a standalone branch.

  2. Commit all the "Generic" features/bugfixes to the generic branch in the future.

  3. Merge changes from the generic branch to client-specific branches.

The problem occurs once I extract the client-specific code, remove all the client-specific features from that branch, apply some new commits and attempt to merge it to the former branch (the client specific one):

enter image description here

As you see, the problem is, that
applies non-desireable changes like commit "1" to the

So the question is: what would be a proper way of extracting the generic features from the existing repository for a purpose of branching different client-specific branches from it in the future?

Answer Source

After you extract non client specific code and create commit (commit-1) from it, you need to merge this commit back to client specific branch. As this merge should not change content of client specific branch, you should use ours merge strategy:

git checkout client-branch
git merge -s ours commit-1

The effective result of this merge is that following merge of generic-branch into client-branch will consider commit-1 as merge base.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download