Let’s meet the smart-dev team. The team is quite small, a few developers, and the project is in the early stage. The team wants to efficiently share code between developers, but prevent the code base from instability when merging new features – in IT this is called continuous code integration. To achieve continuous code integration, the team chose feature branches.
Continuous integration via feature branches
A new feature is developed in a separate branch, and once it is completed and tested, it is merged into the main branch:

A feature is a complete functionality, such as product sales, registration, etc., which usually takes days to implement.
Advantages:
- high stability (few bugs) of the main branch – the whole feature is developed, tested and merged
Disadvantages:
- code is shared infrequently – the feature requires a lot of time to develop and test, so developers can’t use new code until the feature is complete
- time-consuming and complex review – many changes to the source code must be reviewed
- conflicts during merging – many changes in the source code can cause conflicts
This branching strategy worked well for the smart-dev team at the beginning of the project, when the features were small. Over time, the features became more complex. The team noticed that this strategy caused more problems than benefits, so they decided to try a different approach:
Continuous integration via user story branches
Instead of developing and merging an entire feature – large amount of code, the feature is divided into smaller parts – user stories or tasks:

Advantages:
- code is shared more often – developers can use new code, bug fixes enhancements, etc.
- simple code review
- mostly no conflicts during merging
Disadvantages:
- requires work to properly divide features into user stories
- the stability of the code base is lower than in the previous approach, due to the delivery of only part of the feature, which cannot be fully tested until all US’es are completed
- US code affects the main branch/code base, and therefore the behavior of the application
- creating/releasing different versions of the application requires multiple branches/code bases and planning ahead
- need to apply bug fixes/improvements to all versions of the application/release branches
As the project evolved and the smart-dev team had to maintain and release different versions of the application for different clients, the team increasingly felt the disadvantages of this approach. The team started looking for a more flexible solution. They found and tried a new approach:
Continuous integration via feature flags
Feature flags allow for continuous integration/sharing of new code in a safe way. This is achieved by excluding new code functionality from execution:
bool new-feature-turned-on = false
if (new-feature-turned-on)
newGreatFunction()
so the behavior of the application does not change!
The feature code can be constantly safely merged as the feature is disabled from execution:

Of course, during development and testing of feature, the feature is active (new-feature-turned-on flag is true).
The feature can still be divided into smaller parts, but this is not so important from the perspective of continuous integration, because we can deliver the code at any time:

Advantages:
- continuously safely deliver feature-related code, so developers can use new code at any time
- stability of codebase is high – new code does not affect the behavior of the application (if the feature is disabled)
- stability of codebase is high – new feature is enabled after testing and bugfixing
- a single codebase with the ability to enable/disable features to achieve different application behavior – no need to use many branches
- no need to apply bugfixes/improvements to many branches because of single codebase/main branch
Disadvantages:
- one version of the codebase/application may behave differently due to function flags settings, which may be different on various environments or for different clients
- clear, understandable processes and policies must be established to properly manage feature flags
- managing of feature flags
Feature flags gives great flexibility, but they also introduce complexity that you need to be aware of, so please establish clear rules and processes to avoid problems.
Thanks