Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there workflow in git to share same file in multiple branch?

Tags:

git

I have a project targeted to multiple platform. I have to change UI codes for different platform while keeping core classes same. To achieve this, I thought to make git branches for different platform.

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

How to achieve this?

Or is there any other workflow to achieve the same?

like image 878
Pavan Kumar Avatar asked Dec 16 '11 08:12

Pavan Kumar


People also ask

Can two people work on the same file git?

Git can automatically merge the changes, so two people can even work on different parts of the same file and later merge those changes without losing each other's work!

Can we work on multiple branches in git?

Git offers a feature referred to as a worktree, and what it does is allow you to have multiple branches running at the same time. It does this by creating a new directory for you with a copy of your git repository that is synced between the two directories where they are stored.

Which one is the best branching git workflow to follow?

Git Flow. The Git Flow is the most known workflow on this list. It was created by Vincent Driessen in 2010 and it is based in two main branches with infinite lifetime: master — this branch contains production code.

What is Gitflow workflow?

The Gitflow Workflow defines a strict branching model designed around the project release. This workflow doesn't add any new concepts or commands beyond what's required for the Feature Branch Workflow. Instead, it assigns very specific roles to different branches and defines how and when they should interact.


1 Answers

Via git rebase

You may handle your specific platform via git rebase instead of git merge. In this case you will be able to change core branch and than rebase other branches on it keeping platform specific modifications applied over core.

Example workflow.

Make platform branches

git checkout master
git checkout -b platform1

git checkout master
git checkout -b platform2

Make core modifications

git checkout master
# make modification
git commit

Make platform modifications

git checkout platform2
# make modification
git commit

Import core changes in platforms

git checkout platform1
git rebase master

git checkout platform2
git rebase master

Via git merge

It is also possible to use git merge with strategy option as said in git merge manual.

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

This will always choose platform specific changes in case of conflicts.

like image 194
lig Avatar answered Dec 19 '22 02:12

lig