Source Code Management & Branching Policies

Introduction

Effective Source Code Management (SCM) and well-defined branching policies are foundational to successful DevOps practices. They ensure code quality, facilitate collaboration, enable continuous integration and delivery, and provide a clear history of development. This document outlines best practices for SCM, focusing on branching strategies, naming conventions, commit message guidelines, and integration with issue tracking systems like Jira.

For insights into how to name your repositories, please refer to our DevOps Best Practice Document: Repository Naming Conventions.

1. Source Code Management Best Practices

2. Branching Strategies

2.1 GitFlow Workflow

GitFlow is a robust branching model designed for managing large projects with scheduled release cycles. It defines a strict branching model with two main branches (master and develop) and supporting branches for features, releases, and hotfixes.

gitGraph commit id: "Initial Commit" branch develop commit id: "Develop Init" branch feature/add-user-profile commit id: "Feature A" commit id: "Feature B" checkout develop merge feature/add-user-profile tag: "Merge Feature" branch feature/implement-search commit id: "Feature C" checkout develop merge feature/implement-search tag: "Merge Feature 2" branch release/1.0.0 commit id: "Release Prep" checkout main merge release/1.0.0 tag: "Release 1.0.0" checkout develop merge release/1.0.0 tag: "Merge Release to Develop" branch hotfix/fix-login commit id: "Hotfix A" checkout main merge hotfix/fix-login tag: "Hotfix Deployed" checkout develop merge hotfix/fix-login tag: "Merge Hotfix to Develop"

Pros of GitFlow

Cons of GitFlow

2.2 GitHub Flow (Preferred)

GitHub Flow is a lightweight, continuous delivery-oriented branching model. It's simpler than GitFlow and focuses on a single main branch and short-lived feature branches.

gitGraph commit id: "Initial Commit" branch feature/new-dashboard commit id: "Dashboard Work 1" commit id: "Dashboard Work 2" checkout main merge feature/new-dashboard tag: "PR #123 Merged" branch feature/bugfix-payment commit id: "Payment Fix" checkout main merge feature/bugfix-payment tag: "PR #124 Merged"

Pros of GitHub Flow

Cons of GitHub Flow

2.3 When to Use Which Strategy

3. Branch Naming Policies

Consistent branch naming is essential for clarity and automation.

4. Commit Message Guidelines

Clear and consistent commit messages are vital for understanding project history, debugging, and collaboration.

Examples:

JIRA-789: Feat: Implement search filter on product listing

This commit introduces a new search filter functionality on the product listing page.
Users can now filter products by category and price range.

The implementation includes:
- Frontend components for filter selection.
- API endpoint for filtered product retrieval.
- Unit tests for new components and API.
JIRA-101: Fix: Resolve database connection leak

Identified and fixed a persistent database connection leak in the `UserService` module. 
The `finally` block was missing a call to close the connection, 
leading to resource exhaustion over time.

This fix ensures connections are properly closed after use, improving application stability.

5. Semantic Versioning (SemVer)

Semantic Versioning is a formal convention for version numbers, defined by a three-part number: MAJOR.MINOR.PATCH. This system communicates the nature of changes in each release, making it easier for consumers to understand potential impacts.

Application in SCM:

6. Jira Issue Management Integration

Integrating SCM with Jira streamlines workflow and provides traceability from code changes back to business requirements or bug reports.

7. Pull Request (PR) / Merge Request (MR) Best Practices

Pull Requests are central to code review and quality assurance.


Conclusion

Implementing these DevOps best practices for Source Code Management and branching policies will significantly enhance our development workflow. By adopting clear conventions for branching, naming, and commit messages, and by tightly integrating with our issue tracking system, we ensure a transparent, efficient, and high-quality software delivery pipeline. These practices foster better collaboration, reduce errors, and accelerate our ability to deliver value to our users.