Sitemap
Sanchitha Udana Wijesundara

Sanchitha Udana Wijesundara

DevOps Engineering Enthusiasts | University of Colombo Faculty of Technology - BICT (hons) - Reading

Press enter or click to view image in full size

A good Git branching strategy can help keep your codebase organized, ensure smooth collaboration, and allow for controlled releases and bug fixes. Here are two popular common branching strategies used in Git.

01. Trunk Based

Press enter or click to view image in full size
https://statusneo.com/trunk-based-development/

Trunk-based branching is a development strategy where all developers work on a single branch (called the “trunk” or “main” branch) instead of using long-lived feature branches or multiple branches for individual features. Trunk-based development focuses on frequent integration and small, incremental changes to the main branch.

key concepts of trunk-based branching:

01. Frequent Integration: Developers frequently merge their changes into the trunk (main) branch, often multiple times daily, keeping it up-to-date.

02. Small, Incremental Changes: Features are broken into smaller pieces integrated regularly instead of working in isolation for long periods.

03. Feature Flags: Incomplete features are hidden from users in production using feature flags, allowing integration without affecting the system.

04. Short-lived Feature Branches: If feature branches are used, they are brief and merged back into the trunk quickly to prevent integration issues.

05. Continuous Integration (CI): Automated testing and CI are essential to ensure changes don’t break the build and that the trunk is always in a deployable state.

06. Code Reviews: Code reviews are conducted asynchronously, often alongside frequent integrations, to ensure quality.

Advantages:

  • Faster delivery due to frequent, small changes.
  • Fewer merge conflicts by reducing the number of long-lived branches.
  • Better collaboration by encouraging shared understanding of the codebase.

Challenges:

  • Discipline is required to ensure regular integration without breaking the trunk.
  • Strong CI and automation are needed to maintain quality.
  • Complexity in managing feature flags if not handled properly.

02. Git Flow

Press enter or click to view image in full size
https://nvie.com/posts/a-successful-git-branching-model/

Gitflow is a legacy Git workflow originally a disruptive and novel strategy for managing Git branches. Gitflow has fallen in popularity in favor of trunk-based workflows, which are now considered best practices for modern continuous software development and DevOps practices. Gitflow can also be challenging to use with CI/CD.

Get Sanchitha Udana Wijesundara’s stories in your inbox

Join Medium for free to get updates from this writer.

01. Main branch (master/main): The main branch always reflects the production-ready state. Only release and hotfix branches are merged into it.

02. Develop branch: This branch is used for the latest development code. New features are merged into it and thoroughly tested before creating a release.

03. Feature branches: These branches are used to work on individual features. Feature branches are typically created from the develop branch and merged back when the feature is complete.

04. Release branches: When preparing for a release, a release branch is created from develop. Bug fixes or minor changes for the release can be added to the release branch before merging it into both main and develop.

05. Hotfix branches: Hotfix branches are used to fix urgent issues on the main branch (production). Once fixed, the branch is merged back into both main and develop.

Advantages of Git Flow:

  1. Clear Structure: Provides a well-defined branching structure, making it easier to manage features, releases, and hotfixes.
  2. Isolated Feature Development: Developers can work on separate feature branches without affecting develop or master branches.
  3. Dedicated Release Branches: Allows for testing, bug fixes, and final adjustments before merging into production.
  4. Hotfix Branches: Enables urgent fixes directly on the production (master) branch without interrupting ongoing development.
  5. Parallel Work: Supports multiple developers working on different features simultaneously.
  6. Clear History: Results in an organized Git history, where each branch serves a specific purpose (features, releases, hotfixes).
  7. Supports Continuous Delivery: This can be adapted for continuous delivery with appropriate automation tools.

Challenges of Git Flow:

  1. Increased Complexity: Managing multiple branches adds complexity, especially for smaller teams or projects.
  2. Long-lived Feature Branches: Feature branches can become long-lived, increasing the chance of merge conflicts.
  3. Slower Integration: Delayed integration of features can lead to bigger, more complex merges later on.
  4. Release Management Overhead: Managing release and hotfix branches introduces extra overhead, especially in smaller or fast-moving teams.
  5. Not Ideal for Continuous Integration: Long-lived branches can conflict with CI/CD best practices, making continuous integration more difficult.
  6. Risk of Diverging Codebases: Multiple branches can lead to diverging codebases, making merging and integration more challenging.
  7. Learning Curve: New team members may struggle to understand the strict branching conventions used in Git Flow.

Choosing the Right Strategy

The best strategy depends on the size of the team, the complexity of the project, and the frequency of releases:

  • For smaller teams/projects: Trunk-Based Development works well for simple, continuous deployments.
  • For larger teams/projects: Git Flow is more suitable when releases need to be controlled or you maintain multiple environments.

--

Sanchitha Udana Wijesundara
Sanchitha Udana Wijesundara

Written by Sanchitha Udana Wijesundara

DevOps Engineering Enthusiasts | University of Colombo Faculty of Technology - BICT (hons) - Reading