1

I am looking for a way to be able to manage custom deviations from a master REPO which has common code shared by all, and individual custom code which is specific only to that particular branch.

I am using the term 'BRANCH' for this generically as I am not sure if that is the correct term to use for this kind of scenario.

The Reason for requiring this, is I have a standard application which gets deployed in multiple locations, but each location may also have overrides and custom code specific to that install.

As all branches share 95% of the same common code as the master, I do not want to have to maintain each branch separately, when the master / common code is updated, but as each branch has custom code specific only to that branch, I also need to be able to maintain each branch's custom code independently and be able to clone the code for each branch independently of the master and other branches.

Is there a clean way of achieving this using GIT ?

crankshaft
  • 2,607
  • 4
  • 45
  • 77
  • I think you can accomplish what you want by making branches for each location, keeping most of the code in master, and constantly doing `git rebase master` in each of the branches to keep up with it. You don't ever have to merge the branches back. – Jim Stewart Jan 15 '14 at 04:14
  • @JimStewart You don’t need to be constantly rebasing, and you also shouldn’t. As the custom branches have their own changes, you would constantly need to rewrite *all* the commits that are unique to the branch, which quickly add up, and likely generate more problematic merge conflicts. This would also break any ability to work with a team as the rebased commits will break the compatibility. Instead: **Just merge** from master, pulling in the changes from the standard version. – poke Jan 15 '14 at 07:02

2 Answers2

0

You can setup merge strategies in your git attributes. Check it out here: http://git-scm.com/book/ch7-2.html#Merge-Strategies

Here's a brief snippet from the section:

This is helpful if a branch in your project has diverged or is specialized, but you want to be able to merge changes back in from it, and you want to ignore certain files. Say you have a database settings file called database.xml that is different in two branches, and you want to merge in your other branch without messing up the database file. You can set up an attribute like this:

database.xml merge=ours
StuckOverflow
  • 991
  • 2
  • 10
  • 21
0

If you don't have to merge a change you are doing in a branch dedicated to a certain location (a "location branch"), then you can do as Jim Stewart commented, and simply rebase your location branches on top of master, each time master (which contains the common code) adds new commits.

To rebase all your "locations branches" on top of master, see:


But if you do have to merge back some times, then you can declare in your "location" branches some content filter driver: see "Best practice - Git + Build automation - Keeping configs separate": that would allow you to keep the "data files" (files with data specific to a location) separate from the template files (files used to generate the actual valued file for a given location).
That way, each data file for each location is different, and you can merge both way without having to handle conflicts.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250