Git_Workflow_Patterns - kamialie/knowledge_corner GitHub Wiki

Git Workflow Patterns

Trunk Based Development

Single (main) branch. Commits are made directly to main (short lived branches < 24h). Main branch is always production ready. Robust CI/CD and feature flags are a requirement.

Pros:

  • Simple
  • Codebase is always production ready
  • Production matches latest commit
  • Limited merge conflicts
  • Improved engineer experience

Cons:

  • Robust CI/CD (really good deployment pipeline)
  • Low number of contributors (< 10)
  • Need feature flags
  • Individual work becomes more difficult
  • Limited visibility

Git Flow

Provides established process for delivering hotfixes, strong traceability, auditability, and testing support. Good for software with specific releases.

Long living branches:

  • main
  • develop

Short living branches:

  • feature (branched from develop and merged back upon completion)
  • release (branched from develop, received as little as possible changes, goes through testing and merged to main; also merged back to develop to catch all bug fixes)
  • hotfix (branched from main, and merged both to main and develop upon completion)

Pros:

  • Great for testing and compliance requirements
  • Suits well for large teams
  • Improved traceability between branches and features
  • Supports managing multiple versions

Cons:

  • High learning curve
  • Complex process
  • Lengthy path to production
  • Dedicated role to manage release
  • Frequent merge conflicts

Mutations

GitHub flow has only 2 types of branches: a single main (production) branch and feature branches that are merged directly into it. Can be summarized as feature branching.

Pros:

  • Simple workflow
  • Supports concurrent feature development
  • Single merge point
  • Basic traceability
  • Feature testing

Cons:

  • Limited scaling
  • Limited number of contributors
  • Potentially difficult merge conflicts
  • Robust CI/CD brings full benefit of the workflow

GitLab flow supports a separate testing environment. Contains multiple long-living branches; only short-lived feature branches and no hotfix or release branches. Bug fixes follow same flow as feature branch. Overall simpler workflow that Git flow, provides additional check to production, but prone to high probability of merge conflicts and lack of traceability.

  • main (auto deploys to shared development environment, periodically merged into testing)
  • testing (auto deploys to staging or QA environment, merged into production)
  • production (deploys to production environment)

References