flumpb
flumpb

Reputation: 1776

How can we sync files between two branches in git?

I have forked a project with many branches. Two branches in particular interest me.

1.8.x
2.2.x

I have introduced a new file, 'newfile.source' and changes to a file 'existingfile.source' that exists in both branches. I want to synchronize the changes I make in newfile and existingfile between both branches.

The way I model this in my head is something like this:

commit -- commit -- commit -- commit -- commit -- commit -- commit -- 2.2.x
                            \
                             -- commit -- 1.8.x

I want to have a structure (branch but only consisting of the changes to existingfile and newfile) that I can make changes to and merge into 1.8.x and 2.2.x:

nothing -- custom_changes -- nothing

and then do something like:

git checkout 2.2.x
git merge custom_changes
git checkout 1.8.x
git merge custom_changes

Upvotes: 1

Views: 1137

Answers (1)

KingCrunch
KingCrunch

Reputation: 131921

Just commit it to one branch (like usual). I would prefer the newer one (2.2.x) here. Then switch to the old branch (1.8.x) and "backport" the commit using cherry-pick

Upvotes: 2

Related Questions