Reputation: 1586
I have a base branch with Dolibarr code with custom code. Then I have 2 branches company_a and company_b.
In branch "custom" I make changes to Dolibarr's base code that we want in both companies. Then in each branch I make changes that are only specific to each company.
The problem is when I have to touch core code in company_b and later I make a change for both companies in custom.
If I merge custom to company_b (and it just so happens that I don't get a merge conflict) I lose the changes made in company_b.
How can I deal with this?
According to ChatGPT I could do
git switch company_b
git merge custom
git rebase custom
but š¤·, who knows. I tried just in case and the changes I made in company_b, specifically deleting a part of the code, are missing and the code I deleted is back.
Am I understanding this right??
āāāāāāāāāāāāāāāāāāāāāāāāāāā
| code from custom branch |
āāāāāāāāāāāāāāāāāāāāāāāāāāā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
| code from custom branch | code from company_a branch |
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
| code from custom branch | code from company_b branch |
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
| code from custom branch with changes |
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
| code from custom branch | code from company_a branch | code from custom branch with changes |
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
| code from custom branch | code from company_b branch | code from custom branch with changes |
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
| code from custom branch with changes |
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
| code from custom branch | code from custom branch with changes | code from company_a branch |
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
| code from custom branch | code from custom branch with changes | code from company_b branch |
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
| code from custom branch with changes |
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
| code from custom branch with changes | code from company_a branch |
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
| code from custom branch with changes | code from company_b branch |
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
I think all I need, for my specific case, is to rebase.
That way all changes made in custom will be shared between branches while maintaining branch specific changes.
Can someone confirm?
Upvotes: 2
Views: 77
Reputation: 1324318
The problem is when I have to touch core code in company_b and later I make a change for both companies in custom.
If you do rebase company_b
on top of the base branch custom
(same for company_a
), then both branch can benefit from the common
evolution.
git switch company_b
git rebase common
git push --force
The drawback of that approach is that you will need to force push company branches, which can be problematic if more than one collaborator is working on those branches: that would need to fetch, then rebase their own local commits on top of origin/company_x
, which would have been reset to the new history.
And you might still need to resolve conflicts, but I would look into git rerere
that I mentioned in "Are there any downsides to enabling git rerere?" (to avoid having to resolve them on every rebase).
But, depending on your development workflow (meaning if there is no company local development in progress while those branches are rebase/force pushed), that can still be a valid option.
Upvotes: 1