Gerrit: working with multiple branches & propagating changes

10,475

I would say that it's better, in this case, to merge than to cherry pick.

A cherry pick adds the same changes but not the same commit. So while the source is the same on a cherry pick and merge the git tree is different. When the tree is different and you later do a merge git will think that the commit you previously cherry picked is missing and try to merge that change as well, even if the actual code is already there. That's probably why you get a lot of conflicts.

I would propose another way of working.

  • When you do normal work you develop on feature and push to Gerrit as normal.
  • When you do a patch (ie bug fix) on the stable production environment you do that directly on master (or local branches if you like but not on feature)
  • When the patch as been approved in Gerrit it get's merged into the real master and you can make a pull request to get that change to your local copy. Your version of master is now the same as Gerrits master
  • Now you would merge all new changes on master into feature. Make sure you do a rebase so that the patch ends up before anything you've already done on feature
  • Once it's time to deploy all new features you can merge feature into master, push to Gerrit (if you have permissions you can by pass gerrit by pushing directly to master instead of refs/for/master as these changes are already reviewed)
  • Once all changes are on Gerrits master you do a pull on your master and a merge into feature with rebase making feature a clean branch to work on. It's of course totally valid to have a new feature each release. Both work fine.
Share:
10,475
Tomasz W
Author by

Tomasz W

Updated on June 12, 2022

Comments

  • Tomasz W
    Tomasz W almost 2 years

    I'm trying to identify the proper way of working with multiple branches on Gerrit that would match our workflow.

    The way we work with branches right now is: we have master & feature branch. Master is the branch we want to polish and make it ready for release, while feature is obviously a field of intensive work. Now, in our particular case whenever somebody works on a bug fix, they:

    • create a change targeted for master branch
    • cherry pick it to the feature branch targeted change
    • once gerrit code review completes, submit both changes.

    now the way i understand cherry-pick, it selects individual commit and merges it to the current change. if that is the case, i would expect to have no merge conflicts in the end, and indeed this workflow works perfectly with just GIT. Gerrit, however, most likely due to its nature (branches are not merged remotely the way these are locally and get a different sha tag) lists a tremendous number of conflicting files in the end.

    Now, I resolved all these issues by applying merge strategy (ours on feature, theirs on master), but it does not feel right: if anything was not propagated, it just got discarded.

    My question is: is there a safe workflow, similar to the above one, that would in the end produce a clean merge with gerrit?