Reputation: 101
We have a standard web project and maintain 3 core branches for this project: Master, Beta, and Develop. Here is a summary of the process/workflow that we use:
(1) A new feature/update is requested so we create a new Feature branch.
(2) A commit is made for the new Feature branch and the Feature branch is merged into the 'Develop' branch; the 'Develop' branch is then published to a testing environment to be tested.
(3) Once the new feature is tested/approved, a new pull request is made in the same Feature branch; this new pull request is meant to be merged into the 'Beta' branch.
The 'Beta' branch has all of our "ready-to-go-live" features: in fact, we publish the 'Beta' branch directly to the production environment and when that is ready we immediately merge the 'Beta' branch to the 'Master' branch....by doing this, the 'Master' branch is always a copy of the code that is on the production environment.
The problem: in step 3 above, when we try to merge the new Feature branch into the 'Beta' branch, the pull request includes ALL new commits that have been merged into the 'Develop' branch.
Example: 5 feature branches are individually merged to the 'Develop' branch (branches are labeled 1, 2, 3, 4, and 5). All 5 are tested, but there are bugs with the first 4. So branch "5" is approved and we try to create a pull request for that Feature branch and merge it to 'Beta'....but when we do that, the pull request includes all 5 feature branches....not just the commit for branch "5".
We MUST be doing something wrong! What can we do to fix our process/workflow?
Upvotes: 8
Views: 2048
Reputation: 979
I would be doing the follow steps.
I will keep in mind the following things .
Upvotes: 1
Reputation: 1539
You say that merging feature 5 into beta will bring features 1-4 into beta as well. If so, the commits for features 1-4 are definitely in the feature 5 branch. There are 3 ways that could happen:
Feature 5 was branched out from develop after features 1-4 were merged into develop.
Develop was merged into feature 5 (upmerge) after features 1-4 were merged into develop.
Features 1-4 were merged directly into feature 5.
Beware that a branch contains not just the commits made directly to the branch, but also all commits from the beginning of the repo up to the branching point, and any commits in branches merged into the branch.
BTW, the 3 points above hold even if you change 'merge' to 'rebase', or 'develop' to any other branch.
Upvotes: 1
Reputation: 67297
(3) Once the new feature is tested/approved, a new pull request is made in the same Feature branch; this new pull request is meant to be merged into the 'Beta' branch.
The 'Beta' branch has all of our "ready-to-go-live" features: in fact, we publish the 'Beta' branch directly to the production environment and when that is ready we immediately merge the 'Beta' branch to the 'Master' branch....by doing this, the 'Master' branch is always a copy of the code that is on the production environment.
The problem: in step 3 above, when we try to merge the new Feature branch into the 'Beta' branch, the pull request includes ALL new commits that have been merged into the 'Develop' branch.
No, that does not make sense. If that happens you have omitted important information such as:
In each of these cases your workflow is fundamentally broken and cannot work with regard to your idea of a beta branch. So if you want to avoid cherry-picking (bad! bad! bad!) how can you achieve what you want to do? There are some basic options:
Upvotes: 6
Reputation: 1324148
You're correct, our workflow differs from the traditional GitFlow. Feature branches are merged into EITHER
develop
orbeta
, entirely independently.Once the new feature is tested/approved, a new pull request is made in the same Feature branch
f2--f2--f2 (f2)
/ \
d--d--d--D1-------D2 (develop)
\ /
f1---f1
a bunch of unwanted/unrelated feature branch commits are merged into "beta" as well
Strange: that would be as if f2 was on the D2 merge commit (which has f2 but also f1).
For testing, could you try in command-line to cherry-pick the exact commits you want, then merge 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 validate you only get the exact f2
merged branch you want in beta, and not all the other features.
Once that is validated, we can work on doing the same from a GUI (like for instance SourceTree)
Upvotes: 1
Reputation: 87
Once you merge a branch with another, the merging branch commits get commited on the home branch.
What you probably want to be doing is not even work on the development branch for development, but rather branch out of it for each feature (serialize the features, of course) which are then separately checked for bugs before merging packages of many feature branches into the development branch.
To get rid of bugs that got into the development branch anyway you will need to get the code working on the feature branch and then merge that OR revert the changes by reverting the feature branch using git revert
and then merging the branch again (effectively reverting only the commits that it introduced to the development branch.
Reverting on the development branch (or any of the bigger branches in your hierarchy) is generally ill advised in the industry, except when you merge just a single feature... as different commits can establish dependencies between themselves and reverting can cause more harm than it solves.
To get a better hang on reverting read this guide by atlassian or the available documentation.
Upvotes: 1
Reputation: 166
That's the way git works. You'll need to create separate branches for each feature.
Upvotes: 1