Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to forbid Git merge certain branches

Tags:

git

merge

I need support of 3 versions of my program. Where most files are

joint (common) but several files contain different content for each version.

I'll probably use 4 branches A,B,C,D in Git.

Form example project Ice-cream:

____________________________________________________
Cup.txt: { Waffle cup } – common file for all version

Filling.txt { banana } - special file for B version
Filling.txt { strawberries } - special file for C version
Filling.txt { vanilla } - special file for D version
____________________________________________________

A - branch suitable only for global files (Cup.txt)

B,C,D - branch suitable only for Filling.txt file.

For this strategy I need allow to merge only in one direction: A => B,C,D

My question is how to forbid merging from B,C,D to A branches in Git?

how to forbid merging reverse direction

like image 583
Jarikus Avatar asked Dec 10 '25 19:12

Jarikus


1 Answers

Regarding source code, it is best to avoid complex merge strategy, and modify PrintBill in order to:

  • separate content specific to client A and B
  • build the right executable for client A and client B by choosing the right source

The idea is the same than the one initially written below: avoid any complex merge strategy.

Now if that kind of refactoring isn't possible, you can try and declare a merge driver, but that won't be always called (only in case of conflicts)


Another approach would be to avoid versioning Filling.txt (that way, no more merge strategy headache).

You can:

  • version 3 different files with values for each environment
  • setup a smudge script (a content filter driver declare in a .gitattributes file) which will automatically on checkout generate, depending on the checked out branch, the right Filling.txt

smudge

like image 61
VonC Avatar answered Dec 12 '25 11:12

VonC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!