I have some branches: branch 1 and branch 2. They have their origin from the master branch. Now there were some changes in the master branch. One is a critical bugfix, which has to be imported on branch 1 and 2. But there is a change (or perhaps multiple) which should not be imported on the other branches.
How is that solved in the GIT world?
One idea I came up with is to create the bugfix branch before the other changes are made to the master branch. This would work if you go back in history and you know that at that point the branches 1 and 2 are using the same code base as in the master branch.
What if branch 1 and 2 contain different versions of the master, but the affected code is the same?
branch 1: master v1.0
branch 2: master v1.1
I can't merge the latest version of the master into the other branches, because there are changes, which the branches shouldn't get yet. Should the changes be made in every branch?
Merge instead of cherry-pick!
cherry-pick
makes a new commit on your branch, and that commit doesn't not refer to where the bugfix was originally created, hiding actual history. Furthermore, the bugfix could be several commits, or have further development in the future (like, it didn't turn out to really fix it the first time). This makescherry-pick
inconvenient.I'd much rather
merge
the bugfix branch. When you created the bugfix commit on master, surely you had a branch there?Done! The nice thing with this is that you don't have duplicate commits doing the same thing. Your history reflects also what you actually did, work on a branch, integrate its changes to other branches.
If you don't have the branch
bugfix_1234
anymore, you can always recreate one, or an annotated tag.Look at the red dot in this git workflow, it's exactly what it is doing.
Edit: as per your comment in another answer, you need your bugfix (hotfix in the workflow) to be based on a common ancestor of the branches and master. If the fix applies to both the branches and master, it makes sense anyway.