Overview
This document outlines an enterprise-level Git strategy using a Single Trunk approach with the master/main branch as the primary development line. This strategy emphasizes:
- Continuous Integration: All changes are integrated frequently into the main branch
- Tag-based Deployments: Deployments are triggered by Git tags on the main branch
- Approval-based CD: Deployments require approval gates for production environments
- Branch-based Testing: Feature and release branches are used for testing before merging
Key Principles
- Always Deployable
master/mainbranch is always deployable - Short-lived All features are developed in short-lived feature branches
- Tag-triggered Tags trigger the CI/CD pipeline
- Automated Testing Automated testing at every stage
- Manual Approval Manual approval gates for production deployments
Branch Strategy
Main Branch: master/main
- Purpose: Production-ready code
- Protection: Protected branch with required PR reviews
- Deployment: Only tagged commits are deployed
- Merge Strategy: Squash and merge or merge commits (consistent across team)
Supporting Branches
1. Feature Branches
Naming: feature/JIRA-123-description
Example: feature/USER-456-user-authentication
Lifetime: Short-lived (1-2 weeks max)
Purpose: Individual feature development
2. Release Branches
Naming: release/v1.2.0
Example: release/v2.1.0
Lifetime: Until release is deployed and stable
Purpose: Release preparation and bug fixes
3. Hotfix Branches
Naming: hotfix/v1.2.1-critical-bug
Example: hotfix/v2.1.1-security-patch
Lifetime: Very short-lived (hours to days)
Purpose: Critical production fixes
CI/CD Pipeline Architecture
Pipeline Triggers
| Trigger | Branch/Tag | Actions | Deployment |
|---|---|---|---|
| Pull Request | feature/*, release/* | Build, Test, Security Scan | None |
| Tag (Development) | v*-dev, v*-rc* | Full Pipeline | Development/Staging |
| Tag (Production) | v* (release tags) | Full Pipeline + Approval | Production |
Workflow Scenarios
Scenario 1: New Feature Development
Complete lifecycle of developing a new feature from conception to production deployment.
Step 1: Create Feature Branch
# Sync with latest master
git checkout master
git pull origin master
# Create feature branch
git checkout -b feature/USER-456-user-authentication
Planning Phase:
- Ensure feature is well-defined with clear acceptance criteria
- Use consistent naming convention with ticket/story number
- Always branch from latest master to avoid integration conflicts
- Inform team about new feature branch to avoid duplicate work
Step 2: Development and Testing
# Make incremental changes
git add .
git commit -m "feat: add user authentication service"
git commit -m "feat: add password validation rules"
git commit -m "test: add unit tests for authentication service"
# Push feature branch
git push origin feature/USER-456-user-authentication
Development Best Practices:
- Make small, frequent commits with clear commit messages
- Run unit tests locally before each push
- Follow coding standards and run linters
- Update documentation as you develop
- Use conventional commit format (feat, fix, docs, etc.)
Step 3: Create Pull Request
PR Requirements Template:
## Summary
Brief description of what this PR does
## Changes Made
- List of specific changes
- New features added
- Bug fixes included
## Testing
- Unit test coverage: X%
- Integration tests: Pass/Fail
- Manual testing performed
- Performance impact assessment
## Breaking Changes
List any breaking changes
## Checklist
- [ ] Tests pass
- [ ] Documentation updated
- [ ] Code review completed
- [ ] Security review (if applicable)
Step 4: Code Review and Merge
# After approval, merge to master
git checkout master
git pull origin master
git merge --squash feature/USER-456-user-authentication
git commit -m "feat: Add user authentication module (USER-456)"
git push origin master
# Clean up feature branch
git branch -d feature/USER-456-user-authentication
git push origin --delete feature/USER-456-user-authentication
Review Process:
- Minimum 2 reviewers required (technical + domain expert)
- Reviews completed within 24-48 hours
- All reviewers must approve before merge
- Address all review comments before merging
Scenario 2: New Release Process
End-to-end release process from planning to production deployment.
Step 1: Create Release Branch
# From master, create release branch
git checkout master
git pull origin master
git checkout -b release/v1.3.0
git push origin release/v1.3.0
Release Planning:
- Define release scope and included features
- Create release notes draft
- Schedule release timeline with all teams
- Feature freeze - no new features after branch creation
Step 2: Release Preparation
# Update version numbers and documentation
# Update CHANGELOG.md
git add .
git commit -m "Prepare release v1.3.0"
git push origin release/v1.3.0
Preparation Tasks:
- Update package.json, version files, and configuration
- Update CHANGELOG.md with all changes since last release
- Update API documentation and user guides
- Ensure database migration scripts are included
- Validate environment-specific configurations
Step 3: Release Testing
Comprehensive Testing Phase:
- Automated Testing: Full regression, integration, performance, security testing
- Manual Testing: User acceptance testing, exploratory testing, UI testing
- Environment Testing: Deploy to testing environment and validate procedures
Step 4: Tag and Deploy
# When ready for release
git checkout master
git pull origin master
git tag -a v1.3.0 -m "Release v1.3.0: User authentication and notifications"
git push origin v1.3.0
# This triggers the CD pipeline
Deployment Process:
- Pre-deployment checklist completed
- Use semantic versioning with comprehensive tag message
- Monitor application health during deployment
- Run smoke tests after deployment
Scenario 3: Hotfix Process
Emergency hotfix process for critical production issues that cannot wait for next release.
Step 1: Identify Critical Issue
Severity Classification:
- Critical Complete system outage, data loss, security breach
- High Major feature broken, significant user impact
- Medium Minor feature issues, workaround available
Step 2: Create Hotfix Branch
# Create hotfix branch from the problematic tag
git checkout v1.2.1
git checkout -b hotfix/PROD-789-security-patch
Step 3: Implement Fix
# Implement minimal fix
git add .
git commit -m "fix: Apply security patch for user authentication"
git push origin hotfix/PROD-789-security-patch
Fix Implementation Guidelines:
- Make the smallest possible change to fix the issue
- Strictly bug fixes only - no feature additions
- Add tests that would have caught the issue
- Document the fix and its rationale
Step 4: Merge and Emergency Deploy
# Merge to master
git checkout master
git merge hotfix/PROD-789-security-patch
git push origin master
# Create hotfix tag
git tag -a v1.2.2 -m "Hotfix v1.2.2: Critical security patch"
git push origin v1.2.2
Emergency Deployment:
- May bypass normal approval processes for critical issues
- Enhanced monitoring during and after deployment
- Have immediate rollback plan ready
- Immediate verification that issue is resolved
Scenario 4: PR Testing Environment Deployment
Automated testing environment deployment for pull requests to validate changes before merging.
Testing Environment Strategy
- Mirrors production configuration with synthetic test data
- Isolated environment automatically provisioned per PR
- Triggered by PR labels (e.g., "deploy-testing") or comments
Automated Deployment Process
# Use PR labels or comments to trigger testing deployment
# Label: "deploy-testing"
# Comment: "/deploy testing"
Environment Provisioning:
- Spin up dedicated testing environment
- Deploy PR branch code with test data
- Run health checks and provide access links
- Comment on PR with deployment status and links
Testing Activities
- Automated Tests: Full test suite against deployed environment
- Manual Testing: Exploratory testing by developers and QA
- Integration Testing: Validate with external test services
- User Acceptance: Business users validate functionality
Scenario 5: Staging Environment Deployment
Pre-production validation in production-like environment after code review approval.
Staging Deployment Criteria
- Code review approved by minimum 2 reviewers
- All automated tests passing
- Testing environment validation completed
- Security review completed (if applicable)
- Senior developer or tech lead approval required
Staging Environment Characteristics
- Production Parity: Mirrors production environment exactly
- Data: Production-like data (anonymized/masked)
- Monitoring: Full monitoring and alerting enabled
- Access: Limited to authorized personnel
Validation Activities
- User acceptance testing by business users
- Full integration with production-like services
- Load testing under realistic conditions
- Security validation in production-like environment
- Data migration testing (if applicable)
Scenario 6: Reverting a PR in Staging
Emergency revert process when issues are discovered in staging environment.
Option A: Revert the Merge Commit
# If PR was already merged to master
git checkout master
git revert -m 1 <merge-commit-hash>
git commit -m "Revert: USER-456 due to staging issues"
git push origin master
# Create new tag for emergency revert
git tag -a v1.2.3 -m "Revert v1.2.3: Emergency revert of USER-456"
git push origin v1.2.3
Option B: Hotfix Branch for Revert
# Create hotfix branch to revert changes
git checkout master
git checkout -b hotfix/revert-user-456
git revert <commit-hash>
git push origin hotfix/revert-user-456
# Follow hotfix process for deployment
Post-Revert Activities
- Immediate deployment of reverted code to staging
- Confirm the issue is resolved
- Conduct thorough root cause analysis
- Add tests that would have caught the issue
- Review and improve testing/review processes
Scenario 7: Selective Feature Release
Cherry-pick strategy when business decides to release only a subset of features from a release branch.
Situation Assessment
# Check current release branch and its features
git checkout release/v1.3.0
git log --oneline --grep="feat:"
# List all feature branches merged into this release
git log --merges --oneline
Example Scenario:
- Release branch contains 10 features, all tested and ready
- Business decides only 7 features approved for production
- Need selective release while maintaining traceability
Option A: Cherry-pick Approved Features (Recommended)
# Create new release branch for selective features
git checkout master
git pull origin master
git checkout -b release/v1.3.0-selective
# Cherry-pick only approved features in chronological order
git cherry-pick <feature-1-commit>
git cherry-pick <feature-2-commit>
# ... continue for all approved features
Option B: Revert Unwanted Features
# Start with full release and revert unwanted features
git checkout release/v1.3.0
git checkout -b release/v1.3.0-partial
git revert <unwanted-feature-1>
git revert <unwanted-feature-2>
# ... continue for all unwanted features
Key Considerations
- Verify feature interdependencies before selective release
- Run full test suite on the partial feature set
- Update release notes to reflect actual features included
- Communicate changes to all stakeholders
Scenario 8: Multi-Environment Feature Flag Rollout
Progressive rollout of features across different environments using feature flags, allowing for controlled exposure and quick rollback.
Step 1: Prepare Feature with Feature Flags
# Deploy feature with flags disabled by default
git checkout master
git pull origin master
git tag -a v1.3.1 -m "Release v1.3.1: New features with feature flags"
git push origin v1.3.1
Feature Flag Implementation:
- Code Implementation: Wrap new features in feature flag conditions
- Configuration Management: Environment-specific flag configurations
- Monitoring Setup: Track feature usage and performance metrics
- Rollback Mechanism: Instant disable capability without redeployment
Step 2: Progressive Environment Enablement
Rollout Strategy:
- Staging 100% enabled for full testing
- UAT 100% enabled for business validation
- Production Progressive rollout (10% → 25% → 50% → 100%)
- Monitoring Real-time metrics and error tracking at each stage
Scenario 9: Cross-Team Dependency Management
Handle complex dependencies between features developed by different teams that must be coordinated for release.
Step 1: Identify Dependencies
# Team A working on feature/AUTH-123-user-service
# Team B working on feature/UI-456-user-interface
# Team C working on feature/API-789-user-endpoints
# All three features depend on each other
Dependency Mapping:
- Technical Dependencies: Code-level dependencies between features
- Business Dependencies: Features that must be released together
- Timeline Dependencies: Features with specific sequencing requirements
- Integration Points: Shared APIs, databases, or services
Step 2: Coordinate Integration Branch
# Create integration branch for cross-team coordination
git checkout master
git pull origin master
git checkout -b integration/user-management-release
# Teams merge their features into integration branch
git merge feature/AUTH-123-user-service
git merge feature/UI-456-user-interface
git merge feature/API-789-user-endpoints
Integration Process:
- Integration Branch: Dedicated branch for coordinating dependent features
- Regular Syncing: Daily merges from individual feature branches
- Conflict Resolution: Immediate resolution of integration conflicts
- Joint Testing: Cross-team testing in integration environment
Scenario 10: Emergency Production Patch During Active Release
Apply critical patches while a regular release is in progress, requiring careful coordination.
Step 1: Assess Conflict Between Emergency and Regular Release
Current State:
- release/v1.4.0 branch in UAT testing phase
- Critical security issue found in production v1.3.5
- Need emergency patch without disrupting regular release
Conflict Assessment:
- Timeline Conflict Emergency patch vs. scheduled release
- Code Conflict Potential overlapping changes
- Resource Conflict Team availability and focus
Step 2: Parallel Track Strategy
# Create hotfix from current production
git checkout v1.3.5
git checkout -b hotfix/SECURITY-001-critical-patch
# Implement and test hotfix
git add .
git commit -m "fix: Critical security patch"
git push origin hotfix/SECURITY-001-critical-patch
# Deploy hotfix immediately
git checkout master
git merge hotfix/SECURITY-001-critical-patch
git tag -a v1.3.6 -m "Hotfix v1.3.6: Critical security patch"
git push origin v1.3.6
Step 3: Integrate Hotfix into Active Release
# Merge hotfix into active release branch
git checkout release/v1.4.0
git merge hotfix/SECURITY-001-critical-patch
git push origin release/v1.4.0
# Re-test release with hotfix included
# Continue with regular release process
Scenario 11: Database Schema Migration with Rollback Constraints
Handle complex database migrations that require careful coordination between code deployment and schema changes.
Step 1: Assess Migration Complexity
Migration Strategy:
- Backward Compatibility: Ensure old code works with new schema temporarily
- Multi-Phase Deployment: Separate schema and application deployment phases
- Rollback Planning: Prepare rollback scripts for each migration step
- Data Preservation: Ensure no data loss during migration or rollback
Step 2: Implement Phased Migration
# Phase 1: Add new columns (backward compatible)
git checkout release/v1.4.0
git tag -a v1.4.0-schema -m "Database schema migration phase 1"
# Phase 2: Deploy application code using new schema
git tag -a v1.4.0 -m "Application deployment with new schema support"
# Phase 3: Remove old columns (after validation)
git tag -a v1.4.1 -m "Schema cleanup - remove deprecated columns"
Migration Example:
- Phase 1:
ALTER TABLE users ADD COLUMN new_field VARCHAR(255) DEFAULT NULL; - Phase 2: Deploy application that can use both old and new columns
- Phase 3:
ALTER TABLE users DROP COLUMN old_field;
Scenario 12: Large Merge Conflict Resolution
Handle complex merge conflicts that arise when multiple large features are integrated simultaneously.
Step 1: Identify Conflict Scope
# Multiple features causing complex conflicts
git checkout release/v1.6.0
git merge feature/LARGE-FEATURE-A
# Conflicts detected
git merge --abort
# Analyze conflict scope
git merge-tree $(git merge-base feature/LARGE-FEATURE-A release/v1.6.0) feature/LARGE-FEATURE-A release/v1.6.0
Conflict Analysis:
- File-level Conflicts: Which files have overlapping changes
- Functional Conflicts: Logical conflicts in business logic
- Architectural Conflicts: Conflicting architectural decisions
- Test Conflicts: Overlapping or conflicting test cases
Step 2: Systematic Conflict Resolution
# Create conflict resolution branch
git checkout release/v1.6.0
git checkout -b integration/conflict-resolution
# Merge features one by one
git merge feature/LARGE-FEATURE-A
# Resolve conflicts carefully
git add .
git commit -m "Resolve conflicts for LARGE-FEATURE-A"
git merge feature/LARGE-FEATURE-B
# Resolve additional conflicts
git add .
git commit -m "Resolve conflicts for LARGE-FEATURE-B"
Resolution Strategy:
- Sequential Integration: Merge features one at a time
- Expert Consultation: Involve original feature developers
- Comprehensive Testing: Test after each conflict resolution
- Documentation: Document resolution decisions for future reference
Scenario 13: Compliance and Audit Trail Management
Maintain detailed audit trails and compliance requirements throughout the development and deployment process.
Step 1: Establish Audit Requirements
Audit Trail Components:
- Requirements Traceability: Link every commit to business requirement
- Approval Documentation: Record all review and approval decisions
- Deployment History: Maintain complete deployment timeline
- Change Impact Analysis: Document potential impacts of each change
Step 2: Implement Compliance Workflow
# Enhanced commit message format for traceability
git commit -m "feat: USER-123 - Add user authentication
Business Requirement: REQ-456
Approved by: John Doe (Product Owner)
Technical Review: Jane Smith (Tech Lead)
Security Review: Bob Johnson (Security Team)
Impact: New feature, no breaking changes"
Step 3: Digital Signatures for Releases
# Tag releases with compliance information
git tag -s v1.6.0 -m "Release v1.6.0 - Compliance validated
Features: USER-123, USER-124, USER-125
Compliance Officer: Alice Brown
Deployment Window: 2025-07-24 10:00-12:00 UTC
Rollback Tested: Yes
Risk Level: Medium"
Scenario 14: Multi-Region Deployment Coordination
Handle coordinated deployments across multiple geographic regions with different maintenance windows.
Step 1: Plan Multi-Region Strategy
Deployment Regions:
- US East Primary - Deploy first
- EU West Deploy 2 hours later
- Asia Pacific Deploy 4 hours later
Regional Considerations:
- Time Zone Coordination: Plan deployments during local maintenance windows
- Sequential Deployment: Deploy to regions in planned sequence
- Regional Rollback: Ability to rollback specific regions independently
- Data Consistency: Ensure data synchronization across regions
Step 2: Implement Regional Deployment
# Create region-specific tags
git tag -a v1.8.0-us-east -m "Deploy to US East region"
git push origin v1.8.0-us-east
# Monitor US East deployment, then proceed
# 2 hours later
git tag -a v1.8.0-eu-west -m "Deploy to EU West region"
git push origin v1.8.0-eu-west
# Monitor EU West deployment, then proceed
# 2 hours later
git tag -a v1.8.0-asia-pacific -m "Deploy to Asia Pacific region"
git push origin v1.8.0-asia-pacific
Scenario 15: Vendor Integration and Third-Party Dependency Updates
Handle updates to third-party dependencies and vendor integrations that require careful testing and validation.
Step 1: Assess Third-Party Impact
Impact Assessment:
- API Compatibility: Test all integration points
- Security Implications: Validate new security requirements
- Compliance Requirements: Ensure continued regulatory compliance
- Performance Impact: Measure performance changes
Step 2: Coordinate Vendor Integration
# Create vendor integration branch
git checkout master
git checkout -b integration/vendor-payment-v2
# Update vendor SDKs and APIs
# Implement required security changes
# Update compliance handling
# Extensive testing in vendor sandbox environment
# Coordinate with vendor for production cutover
Integration Process:
- Sandbox Testing: Comprehensive testing in vendor test environment
- Gradual Migration: Phase migration from old to new vendor APIs
- Fallback Planning: Maintain ability to revert to previous vendor version
- Monitoring: Enhanced monitoring during vendor integration
Environment Promotion
Environment Strategy
| Environment | Purpose | Trigger | Approval Required |
|---|---|---|---|
| Development | Feature development and unit testing | Feature branch push | None |
| Testing | Integration and system testing | PR creation | None |
| Staging | User acceptance testing | Merge to master | Tech Lead |
| Production | Live system | Version tag | Release Manager + Business |
Promotion Workflow
# 1. Development to Testing (Automatic)
git push origin feature/USER-123
# Triggers testing deployment
# 2. Testing to Staging (After PR merge)
git checkout master
git merge feature/USER-123
git push origin master
# Triggers staging deployment
# 3. Staging to Production (Manual tag)
git tag -a v1.2.0 -m "Release v1.2.0: User authentication"
git push origin v1.2.0
# Triggers production deployment after approval
Best Practices
Commit Messages
Follow conventional commits format:
type(scope): description
feat: add new authentication system
fix: resolve memory leak in user service
docs: update API documentation
chore: update dependencies
Branch Protection Rules
- Require pull request reviews (minimum 2)
- Require status checks to pass before merging
- Require branches to be up to date before merging
- Restrict who can push to matching branches
- Require signed commits for audit trail
- Dismiss stale reviews when new commits are pushed
Security Best Practices
- Signed Commits Enforce GPG signing for all commits
- Secret Scanning Automated scanning for exposed secrets
- Access Control Role-based access with principle of least privilege
- Audit Logging Complete audit trail of all Git operations
Performance Optimization
- Shallow Clones: Use
--depthfor CI/CD to reduce clone time - Partial Clones: Use
--filterfor large repositories - Git LFS: Store large files in Git LFS
- Packfile Optimization: Regular maintenance with
git gc - Reference Repositories: Use reference repos for faster clones
Advanced Git Configuration
# Enforce commit message standards
git config --global commit.template .gitmessage
# Configure advanced merge strategies
git config --global merge.tool vimdiff
git config --global merge.conflictstyle diff3
# Enable rerere for repeated conflict resolution
git config --global rerere.enabled true
# Configure hooks path
git config --global core.hooksPath .githooks
Monitoring and Observability
Key Metrics to Monitor:
- Deployment Frequency How often deployments occur
- Lead Time Time from commit to production
- MTTR Mean time to recovery from incidents
- Change Failure Rate Percentage of deployments causing failures
Troubleshooting & Rollback
Rollback Procedures
1. Quick Rollback (Tag-based)
# Rollback to previous stable version
git tag v2.0.1-rollback
git push origin v2.0.1-rollback
# Trigger deployment pipeline
2. Hotfix Rollback
# Create hotfix branch from last stable tag
git checkout v2.0.0
git checkout -b hotfix/v2.0.1-emergency-fix
# Apply minimal fix
git commit -m "fix: critical security patch"
# Tag and deploy
git tag v2.0.1
git push origin v2.0.1
Common Issues & Solutions
Merge Conflicts
# Update feature branch with latest main
git checkout feature/branch-name
git fetch origin
git rebase origin/main
# Resolve conflicts, then continue
git add .
git rebase --continue
Failed CI/CD Pipeline
Solution: Check pipeline logs, fix issues in feature branch, and re-run pipeline. Never skip CI checks for main branch.