Skip to main content

Branching Strategy for the Project (Gitflow)

1. Introduction to Gitflow​

Gitflow is a popular branching model that helps organize the software development cycle in a clean and systematic way. It defines clear roles for each branch and outlines how they interact. This model supports parallel feature development, smooth release preparation, and quick emergency fixes (hotfixes).

Gitflow centers around two long-lived branches and several short-lived supporting branches to keep the repository stable and manageable.


2. Main Branches​

These are the permanent branches that form the foundation of the project.

a. main (or master)​

Purpose: Stores the code that has been released and is currently running in Production.

Rules:

  • Code in main must always be stable and ready for deployment.
  • Never commit directly to main.
  • Every commit on main should represent a release and must be tagged (e.g., v1.0.0, v1.1.0).

b. develop​

Purpose: Acts as the integration branch, containing the latest completed code that’s ready for the next release.

Rules:

  • All feature branches start from develop.
  • After a feature is completed, it is merged back into develop.
  • The code on develop should always be stable and tested (unit + integration).

3. Supporting Branches​

Short-lived branches created for specific tasks.

a. feature/* (Feature Branches)​

Purpose: Used to develop new features.

Process:

  • Created from: develop
  • Naming: feature/<feature-name> e.g., feature/user-authentication, feature/add-product-to-cart
  • Merged into: develop (after review + testing)

Example:

git checkout develop
git checkout -b feature/add-wishlist

b. release/* (Release Branches)​

Purpose: Prepare a new release — apply small fixes, update version numbers, clean up documentation.

Process:

  • Created from: develop

  • Naming: release/<version> e.g., release/v1.2.0

  • Merged into:

    • main (tag the version)
    • develop (sync the final fixes)

Note: Only small changes here — no large feature work.


c. hotfix/* (Hotfix Branches)​

Purpose: Quickly patch critical issues found in Production.

Process:

  • Created from: main

  • Naming: hotfix/<issue> e.g., hotfix/fix-payment-gateway-bug

  • Merged into:

    • main (tag as a new patch version, e.g., v1.1.1)
    • develop (to sync the fix)

Example:

git checkout main
git checkout -b hotfix/critical-security-patch

4. Example Workflow​

Feature development: “Wishlist”​

  1. Create feature/add-wishlist from develop.
  2. Implement code + tests.
  3. Merge back into develop after review.

Prepare release v2.0.0​

  1. Create release/v2.0.0 from develop.
  2. Apply final fixes + doc updates.
  3. Merge into main, tag v2.0.0.
  4. Merge back into develop.

Critical Production bug in v2.0.0​

  1. Create hotfix/critical-security-patch from main.
  2. Fix + test.
  3. Merge into main, tag v2.0.1.
  4. Merge into develop.

5. Best Practices​

a. Branch Management​

  • Keep branches clean: Delete feature, release, and hotfix branches after merging.

    git branch -d feature/add-wishlist
  • Use Pull Requests: All merges into develop or main must go through PRs.

  • Stay in sync: Keep develop and main updated frequently to prevent large merge conflicts.


b. Commit & Testing Standards​

  • Clear commit messages: Example: Add user authentication endpoint, Fix payment gateway timeout error
  • Always test: Unit tests + integration tests for every feature or fix.
  • Automate CI/CD: Set up pipelines to run tests and quality checks before merging.

c. Versioning​

  • Follow Semantic Versioning: MAJOR.MINOR.PATCH — e.g., v1.2.3
  • Maintain a CHANGELOG.md: Log what changed in each release.
  • Accurate tags: Every tag on main = a real release.

d. Handling Merge Conflicts​

  • Resolve conflicts early: Don’t let them pile up.
  • Careful rebasing: If rebasing a feature branch from develop, communicate with the team.

e. Team Collaboration​

  • Clear ownership: Each developer works in their own feature branch.
  • Consistent communication: Use Slack, Jira, etc., to track progress and merge timelines.
  • Team training: Make sure everyone understands Gitflow before adopting it.

6. Conclusion​

By applying the Gitflow branching model alongside the recommended best practices, the Laptech project gets:

  • A clean and predictable development process
  • Safer and more stable releases
  • Better team collaboration
  • A maintainable, professional codebase