Git : Make the same edits on two different branches at the same time
I would like to know if it’s possible to work on two branches simultaneously if I want to write code that is supposed to be in those two branches. So that, if I commit my changes, it actually updates both branches.
For example :
The code in my branch A is this
print "I like cake"
And the one in my branch B is
print "I love bananas"
But I’d like them both to have this line of code :
print "Everyone loves stackoverflow"
Do I really have to write it in branch A, copy it, checkout B, and paste it ?
Can’t I apply changes to two different branches ?
One Solution collect form web for “Git : Make the same edits on two different branches at the same time”
If you want to work on two branches simultaneously you should seriously think about why you have separate branches to begin with. Branches are usually there so you have separated commits that do not interfere with the other ones.
That being said you could† cherry-pick the commit on B, once it’s done on branch A. This will reapply the commit on the other branch. I.e.
git cherry-pick A to pick the top commit on
A and reapply it to the current branch.
†The problem is that it would try to add the diff, where the line
print "I like cake" is being removed which is not present on branch B, so the patch would fail and as such also the cherry-pick, resulting in a conflict. And that actually makes sense: How exactly should Git know that those two cake/banana-love lines are actually related to each other?