The problem of merging Git Function branch in the Beta branch (after it has already been merged with the Develop branch)

We have a standard web project and support 3 main branches for this project: Master, Beta and Develop. The following is a brief overview of the process / workflow that we use:

(1) A new feature / update was requested, so we create a new Feature branch.

(2) Committing is performed for the new Feature branch, and the Feature branch is in the "Develop" branch; the Develop branch is then published in a test environment that needs to be tested.

(3) After the new function is tested / approved, a new pull request is added to the same Feature branch; This new migration request is for merging into the Beta branch.

The Beta branch has all of our "ready-to-live" functions: in fact, we publish the Beta branch directly in the production environment, and when it is ready, we will immediately merge the beta branch into the Master branch ... . doing this, the branch "Master" is always a copy of the code that is in the working environment.

Problem: In step 3 above, when we try to merge the new Feature branch into the Beta branch, the transfer request includes ALL new commits that have been merged into the Develop branch.

Example: 5 function branches are individually combined with the "Develop" branch (branches are designated 1, 2, 3, 4, and 5). All 5 are tested, but there are errors with the first 4. So, the "5" branch is approved, and we are trying to create a transfer request for this Feature branch and merge it with "Beta" .... but when we do this, a pull request includes all 5 branches of functions ... not just commit for branch "5".

WE SHOULD do something wrong! What can we do to fix our process / workflow?

+7
git merge github
source share
6 answers

(3) After the new function is tested / approved, a new pull request is added to the same Feature branch; This new migration request is for merging into the Beta branch.

The Beta branch has all of our "ready-to-live" functions: in fact, we publish the Beta branch directly in the production environment, and when it is ready, we will immediately merge the beta branch into the Master branch ... . doing this, the branch "Master" is always a copy of the code that is in the working environment.

Problem: In step 3 above, when we try to merge the new Feature branch into the Beta branch, the transfer request includes ALL new commits that have been merged into the Develop branch.

No, that doesn't make sense. In this case, you did not provide important information, for example:

  • Each branch of a new function is separate from another branch. Which development? Then itโ€™s clear that any developmental events are in the history of the newly created function and will also be combined into a beta branch. Git history is a directed acyclic graph, each commit points to one (normal commit) or multiple (merge fix) of the parent commit.
  • In order for functions to merge completely into development, perhaps function branches are regularly rebuilt for development, or perhaps function branches are updated, merging in the latest development, and this makes sense, and I protect it. But in this case, their history contains the entire history of development during the merger / reboot.

In each of these cases, your workflow is fundamentally disrupted, and cannot work with your idea of โ€‹โ€‹a beta branch. Therefore, if you want to avoid picking cherries (bad, bad! Bad!), How can you achieve what you want? There are several basic options:

  • Functional switches: ugly. I would stay away from him whenever possible. The best way to inactivate a function in any branch does not have the corresponding commits in this branch in the first place.
  • Work clean: good. Refrain from merging unverified / unacceptable development features. Combine them only when they are made (as in the โ€œdefinition of doneโ€) and accepted by the client. Make sure you set up an environment that allows your customers to directly test on feature branches instead of washing all of this into a beta branch. Thus, everything that comes to development is essentially ready for production, and you no longer need a beta version. Unfinished work should never be combined into a branch of a higher level. This is what GitFlow is talking about and it works. Even if you do not use GitFlow in its full glory, but simply own, develop and display branches, the validity of my statements remains. I have worked this way in many projects and it works great. In addition, if you think you need another branch to integrate functions for future releases, create a new branch for them "next_release" or "future" and merge them into this branch, and not into development. Then regularly update the future from development, because you also need your features from the current version in a future version, but not vice versa. I hardly believe that this extra step will be necessary, though.
+6
source share

This is how git works. You will need to create separate branches for each function.

+1
source share

After you merge the branch with another, the merge command will be performed on the home branch.

What you probably want to do does not even work in the development branch for development, but rather is separated from it for each function (of course, serializes functions), which are then separately checked for errors before merging packages from function branches into the development branch.

To get rid of errors that fell into the development branch, you will need to get the code working on the branch and then merge this OR revert the changes by returning the function branch using git revert and then merging the branch again (effectively returning only those commits that it introduced into the development branch.

Returning to the development branch (or to any of the larger branches of your hierarchy) is usually not recommended in the industry, unless you combine only one function ... since different commits can establish dependencies with each other and return can cause more harm than he decides.

To get better, return this manual from atlassian or available documentation .

+1
source share

You are right, our workflow is different from traditional GitFlow. Feature branches merge into EITHER develop or beta , completely independently.

After the new feature has been tested / approved, a new interrupt request has been added to the same Feature branch.

  f2--f2--f2 (f2) / \ d--d--d--D1-------D2 (develop) \ / f1---f1 

a bunch of unwanted / unrelated dummy dummy commits are also merged into beta

Strange: it would be as if f2 was on the commit D2 (which has f2, but also f1).

For testing, you can try on the cherry command line to select the exact commits you want , then combine them with --squash .

 git checkout -b tmp develop git cherry-pick $(git merge-base develop f2) f2 git checkout beta git merge --squash tmp 

That way, you can verify that you only get the exact f2 merged branch you want in the beta, and not all other features.
Once this is confirmed, we can work to do the same from the GUI (e.g. SourceTree)

+1
source share

You say merging feature 5 into beta will also add features 1-4 into beta. If so, then the commits for functions 1-4 are definitely in the branches of function 5. There are three ways:

  • Function 5 was branched from development after functions 1-4 were combined into development.

  • The developer was combined with function 5 (acceleration) after functions 1-4 were combined into development.

  • Functions 1-4 were combined directly into function 5.

Beware that the branch contains not only the commits made directly to the branch, but also commits everything from the beginning of the repo to the branch point, and any commit in the branches merges into the branch.

BTW, 3 points above, even if you change 'merge' to 'rebase' or 'develop' to any other branch.

+1
source share

I would take the following steps.

  • Designed feature branches.
  • After completing the function, combine them to develop a branch.
  • When the time comes for testing, I will create a test branch and run the tests there. I will fix any error that will be tested there myself.
  • As soon as my test is successful, I will merge the branch for both the master and the development.
  • Then I would release my code from the main to the beta environment.

I will keep in mind the following things.

  • If a function is not needed for a specific release, I would not combine this function for forking.
  • If I could not solve any errors during testing, I would not release this code, therefore, as in the question, I would solve all the errors and release all the code.
+1
source share

All Articles