Is there a workflow in git for sharing the same file in multiple branches?

I have a project focused on several platforms. I have to change the user interface codes for different platforms, while preserving the kernel classes. To achieve this, I decided to create git branches for different platforms.

Given the above scenario, my requirement is that if I make changes to the main classes, it should be reflected in all git branches.

How to do it?

Or is there another workflow to achieve the same?

+4
source share
2 answers

Via git rebase

You can handle your specific platform with git rebase instead of git merge . In this case, you can change the main branch and reinstall other branches on it, supporting platform-specific kernel modifications.

Workflow example.

Creating Platform Branches

 git checkout master git checkout -b platform1 git checkout master git checkout -b platform2 

Make major changes

 git checkout master # make modification git commit 

Make platform changes

 git checkout platform2 # make modification git commit 

Import major platform changes

 git checkout platform1 git rebase master git checkout platform2 git rebase master 

Via git merge

It is also possible to use git merge with the strategy option, as git says in manual merging .

 git checkout platform2 git merge -s recursive -X ours master 

It will always choose platform-specific changes in case of conflict.

+5
source

There is no such thing in git.

If you are really after git's solution, I suggest creating a “common” branch and merging all your branches.

Always commit changes to the common code for the "common" branch and combine them with the platform branches to prevent conflicts and merging of things that you do not need (or you can choose from cherry).

I also think that you could make the file read-only on the branches of the platform to prevent it from changing without a slap in the face.

CONS: Needed, but it should work.

Alternatively, use different subdirectories for each platform and let your build system insert the necessary files for each build.

CONS: you will not get merges like with git branches.

-1
source

Source: https://habr.com/ru/post/1386665/


All Articles