This question is tagged with Git Flow, and based on that it appears your staging
branch is probably intended to act like the develop
branch in Git Flow, but you are using it slightly differently.
In Git Flow, the develop
branch is intended to be like the master
or main
branch in other flows, in the sense that you merge your code into develop
when you can assume you are pretty sure that code is ready to go to production. From there the release branch is used to verify that you were right with that assumption. The release branch is created for the pending release, and is used to do extra testing, just in case. The release branch simply gives you a branch to make bug fixes if needed, while other features are merged into develop
for the next release after the pending one. This simultaneous development of new features without needing code freezes, while the pending release is being hardened, is the main benefit of using Git Flow. However, unless that release hardening cycle is very short (say, perhaps less than a few hours but very likely less than a day), Git Flow doesn't typically align well with CI/CD practices.
It turns out you aren't using your staging
branch the way Git Flow intends the develop
branch to be used. If you haven't decided which features you want to include in the upcoming release, then they aren't ready to be merged into develop
yet; you need to figure that out a different way, or, consider that perhaps Git Flow may not be the best workflow for you. You could use feature flags (meaning everything is merged into develop
, but a config can be toggled on the release
branch to determine what is turned on), or you could simply revert merges into develop
or even on the release
branch. In your exact situation where 3 features made their way into release
and you decided at that point that you only wish to release one of them, I would recommend simply reverting the 2 merges for the undesired features. You can always add them back in later (by reverting the revert commits, or re-writing the commit IDs and re-merging them).
Note if your situation isn't really an exception and happens often, then I highly recommend using gitworkflow as mentioned in VonC's answer. Note it doesn't even have to be an "either or" decision. In one of the large repos I work out of in my organization, we actually use both: we have a next
branch where we do integration testing, and once those features are validated in the test environment we merge them into develop
over in our Git Flow strategy. The most important thing to remember with "gitworkflow" is that you should reset the next
branch periodically to your main development branch, which is typically main
in some flows, but might be staging
or develop
if you're using a hybrid model.