One of the greatest advantages of Git is its branching capability. This capability allows individuals to have a great deal of freedom in how they choose to share and manage their code. However, for teams to collaborate effectively, a consistent branching strategy should be adopted. A solid branching strategy is crucial to the success of decentralized version control. Concepts that may facilitate this success are feature branches, pull request reviews, and keeping a high-quality master branch.

Feature Branches

Work on features and bug fixes should be kept isolated in feature branches. This helps ensure that the master branch always has production-quality code. Branches in Git are cheap and easy to maintain, so even smaller pieces of work should have their own feature branches. In the case of long-lived feature branches, a feature flag can be an effective tool. A feature flag allows for a change to be merged back into master, but keeps the work hidden from users. Once the feature is complete and ready for production, the feature flag is removed and the feature is rolled out.

Pull Request Reviews

A pull request is a method by which contributions to a project are made. A pull request should be submitted for review each time, before a branch is merged into master. When submitted for review, these pull requests should provide enough detail to allow the reviewer to be quickly brought up to speed. It should also include a method by which it can be tested, such as a build. Additionally, the responsibility to review pull requests should be shared across the team for the greatest efficacy. If a pull request does not pass the review process, it should not be merged into master.

Master Branch Guidelines

A master branch should be high-quality and always up-to-date. This is important because branches created from master are then known to stem from a good version of code. A good practice to follow is to set up a branch policy for the master branch. This policy should require a pull request prior to merging code, as well as a successful build to complete a pull request. It should also add reviewers when a pull request is created. These requirements will help ensure quality and consistency in the master branch.

These are just a few things to get you started with your branching strategy adoption. For more information, or if you need help with your branching strategy, please contact us here at PRAKTIK.