6

I'm using git and I have a repo with a bunch of branches.

If I do a hotfix on branch master (or another branch), how can I easily merge this fix into all those branches. Do I have to merge each branch one by one (like so: Merging one change to multiple branches in Git) or is there an easier way?

Community
  • 1
  • 1
Jayne Mast
  • 1,427
  • 1
  • 16
  • 32

3 Answers3

2

I'd recommend you have a look at git flow and it's tool support.

The hotfix support of git flow is creating a bugfix branch which can be merged into your production branch (probably master) and your development branch (in git flow develop). The hotfix branch starts from master. Since all changes of master are merged into develop after each release you can merge the hotfix branch into develop as well without having to merge commits you didn't intend to be merged.

stigi
  • 6,661
  • 3
  • 40
  • 50
0

I don't think there is any way to merge it into multiple branches with one command. What you can do is which ever branch you start working on just rebase it on master.

Swair
  • 1,503
  • 2
  • 15
  • 27
0

Each merge requires conflict adjudication and sometimes conflict resolution, so there's no way to merge without checking out the branch into which you're merging. That written, do you need to merge it into all your branches?

For example, I have dozens of branches locally, but the vast majority of them are isolated features or fixes. These don't really need most hotfix maintenance commits, and I don't bother to keep them up-to-date until they're production-ready or ready to be shared with collaborators. When they are, they should be brought up-to-date regardless of whether or not master got hotfixed to make the production integration easier.

In other words, my workflow allows me to distribute the trouble of merging hotfixes into feature branches to a time when it actually matters. If you've a bunch of small feature branches, you might not need that hotfix code just yet.

Christopher
  • 42,720
  • 11
  • 81
  • 99