Back to Blog
GitVersion ControlWorkflowsTeam Collaboration

Git Workflow Strategies for Development Teams

Choose the right Git workflow. From Git Flow to GitHub Flow to trunk-based development for your team.

B
Bootspring Team
Engineering
June 5, 2024
5 min read

The right Git workflow keeps your team productive and your codebase stable. Here's how to choose and implement the workflow that fits your team.

Git Flow#

Structure#

main (production) └── develop (integration) ├── feature/user-auth ├── feature/payment-system └── feature/dashboard release/1.0 └── (branches from develop, merges to main and develop) hotfix/critical-bug └── (branches from main, merges to main and develop)

Commands#

1# Start a feature 2git checkout develop 3git checkout -b feature/user-auth 4 5# Work on feature 6git add . 7git commit -m "Add user authentication" 8 9# Finish feature 10git checkout develop 11git merge --no-ff feature/user-auth 12git branch -d feature/user-auth 13 14# Start a release 15git checkout develop 16git checkout -b release/1.0 17 18# Finish release 19git checkout main 20git merge --no-ff release/1.0 21git tag -a v1.0.0 -m "Version 1.0.0" 22git checkout develop 23git merge --no-ff release/1.0 24git branch -d release/1.0 25 26# Hotfix 27git checkout main 28git checkout -b hotfix/critical-bug 29# Fix the bug 30git checkout main 31git merge --no-ff hotfix/critical-bug 32git tag -a v1.0.1 -m "Hotfix 1.0.1" 33git checkout develop 34git merge --no-ff hotfix/critical-bug 35git branch -d hotfix/critical-bug

When to Use#

Good for: ✓ Scheduled releases ✓ Multiple versions in production ✓ Strict release management ✓ Large teams with defined roles Not ideal for: ✗ Continuous deployment ✗ Small, agile teams ✗ Simple projects

GitHub Flow#

Structure#

main (always deployable) ├── feature/add-search ├── fix/login-bug └── update/dependencies

Process#

1# 1. Create branch from main 2git checkout main 3git pull origin main 4git checkout -b feature/add-search 5 6# 2. Make changes and commit 7git add . 8git commit -m "Add search functionality" 9git push -u origin feature/add-search 10 11# 3. Open Pull Request on GitHub 12# - Request reviews 13# - Run CI/CD checks 14# - Discuss changes 15 16# 4. Deploy to staging (optional) 17# - Test in production-like environment 18 19# 5. Merge to main 20# - Squash or merge commit 21# - Delete branch 22 23# 6. Deploy to production 24# - Automated after merge

When to Use#

Good for: ✓ Continuous deployment ✓ Simple release process ✓ Small to medium teams ✓ Web applications Not ideal for: ✗ Multiple production versions ✗ Long release cycles ✗ Complex release management

Trunk-Based Development#

Structure#

main (trunk) ├── short-lived-branch-1 (< 1 day) ├── short-lived-branch-2 (< 1 day) └── (direct commits for small changes)

Process#

1# Small changes: commit directly 2git checkout main 3git pull origin main 4# Make small change 5git add . 6git commit -m "Fix typo in header" 7git push origin main 8 9# Larger changes: short-lived branch 10git checkout main 11git pull origin main 12git checkout -b add-button 13# Work for a few hours max 14git add . 15git commit -m "Add submit button to form" 16git checkout main 17git pull origin main 18git merge add-button 19git push origin main 20git branch -d add-button

Feature Flags#

1// Use feature flags for incomplete features 2const features = { 3 newCheckout: process.env.ENABLE_NEW_CHECKOUT === 'true', 4 darkMode: process.env.ENABLE_DARK_MODE === 'true', 5}; 6 7function CheckoutPage() { 8 if (features.newCheckout) { 9 return <NewCheckout />; 10 } 11 return <OldCheckout />; 12}

When to Use#

Good for: ✓ Continuous integration ✓ High-performing teams ✓ Rapid iteration ✓ Teams with strong testing Not ideal for: ✗ Teams without CI/CD ✗ Inexperienced developers ✗ Complex feature work

Branch Naming Conventions#

1# Feature branches 2feature/user-authentication 3feature/JIRA-123-add-search 4feat/payment-integration 5 6# Bug fixes 7fix/login-redirect 8bugfix/null-pointer 9hotfix/security-patch 10 11# Other types 12docs/update-readme 13refactor/extract-user-service 14test/add-integration-tests 15chore/update-dependencies

Commit Message Conventions#

1# Conventional Commits 2<type>[optional scope]: <description> 3 4[optional body] 5 6[optional footer(s)] 7 8# Types 9feat: New feature 10fix: Bug fix 11docs: Documentation 12style: Formatting (no code change) 13refactor: Code restructuring 14test: Adding tests 15chore: Maintenance 16 17# Examples 18feat(auth): add password reset functionality 19 20fix(api): handle null response from payment gateway 21 22Closes #123 23 24docs: update API documentation for v2 endpoints 25 26refactor(user): extract validation into separate module 27 28BREAKING CHANGE: User.validate() now returns a Result type

Pull Request Best Practices#

1## PR Template 2 3### Description 4Brief description of what this PR does. 5 6### Type of Change 7- [ ] Bug fix 8- [ ] New feature 9- [ ] Breaking change 10- [ ] Documentation update 11 12### How Has This Been Tested? 13- [ ] Unit tests 14- [ ] Integration tests 15- [ ] Manual testing 16 17### Checklist 18- [ ] Code follows style guidelines 19- [ ] Self-review completed 20- [ ] Comments added for complex code 21- [ ] Documentation updated 22- [ ] No new warnings

Comparison#

| Workflow | Complexity | Best For | Release Style | |-------------|------------|--------------------| --------------| | Git Flow | High | Versioned software | Scheduled | | GitHub Flow | Low | Web apps | Continuous | | Trunk-Based | Medium | Mature teams | Continuous |

Conclusion#

There's no universally "best" workflow. Git Flow suits structured releases, GitHub Flow works for continuous deployment, and trunk-based development excels with experienced teams.

Start simple with GitHub Flow, and evolve as your team's needs grow.

Share this article

Help spread the word about Bootspring