1

Let me explain. A "branch" of our firm in another town is also going to use our app created for our specific purposes. But there are bunch of files that will be different for them permanently, other are common. I'm looking for a solution that will prevent overwriting these files accidentally (and maybe remove the need of merging two branches every time?).

Currently we have two branches, let's say [devWe] and [devThey]. Every time people merge them, they have to avoid overwriting these files, which exists in both branches but have sometimes slightly different content, which also to be modified sometimes. We've switched to git recently, so that's not that obvious atm. Let's say files A,B,C,D are "branch-specific". Any ideas?

We tried to keep all common files in main branch, only these specific files in sub branches but that caused many problems, people were not aware of current v of files they are working on etc.

What soulution would you suggest basing on your experience?

Damian K.
  • 172
  • 8
  • Each team gets two branches. "devCommonA" is branched from dev. "devPrivateA" is branched from devCommonA. Changes meant to be shared go into devCommonA. Changes which stay private go into devPrivateA. Merge devCommonA to devPrivateA to test changes. Merge devCommonA to dev to share results with other teams. – Raymond Chen Dec 22 '22 at 10:13
  • Note that Git does not have "branch-specific files": files are stored in *commits*, and any given commit can be on *many branches at the same time*. Suppose commit `c456789` is on both branches GroupA *and* GroupB. How will file `A` in this commit be *both* GroupA *and* GroupB specific? That said, if you're careful never to allow a particular commit to be on two or more branches, you can get the effect you want—but it's not a natural way to work in Git. – torek Dec 22 '22 at 16:31
  • 2
    Frankly, I would change the model completely. Don't use branches, instead, have site-specific files that are installed in your deployment procedure. Those site specific files would all exist in the main branch, simply, but your deployment script would have a site-specific configuration parameter to pick the right set of site-specific branches. – joanis Dec 22 '22 at 19:21

1 Answers1

0

One possible solution is: You can use git attributes in order to ignore changes on the common files when merging back to master: https://git-scm.com/book/en/v2/Customizing-Git-Git-Attributes#_merge_strategies

peregine
  • 3
  • 3