The right Git workflow improves collaboration and deployment reliability. This guide compares popular strategies and when to use them.
GitHub Flow#
Simple and effective for continuous deployment:
main ─────●─────●─────●─────●─────●─────
\ /
feature ●───●───●
Workflow#
1# Create feature branch
2git checkout -b feature/add-login
3
4# Make commits
5git add .
6git commit -m "feat: add login form"
7
8# Push and create PR
9git push -u origin feature/add-login
10
11# After review, merge to main
12# Deploy automatically from mainBest For#
- Small teams
- Continuous deployment
- Web applications
GitFlow#
Structured releases with multiple environments:
main ─────●───────────────●─────────
\ /
release \───●───●───/
\ /
develop ●───●───●───●───●───●───●───●
\ /
feature ●───●
Branch Types#
1# Feature branches
2git checkout -b feature/user-auth develop
3
4# Release branches
5git checkout -b release/1.2.0 develop
6
7# Hotfix branches
8git checkout -b hotfix/security-patch mainBest For#
- Scheduled releases
- Multiple environments
- Mobile apps, desktop software
Trunk-Based Development#
Fast iteration with short-lived branches:
main ─────●─────●─────●─────●─────●─────
\ / \ /
●─● ●─●
(< 1 day) (< 1 day)
Workflow#
1# Small, focused branches
2git checkout -b fix-button-style
3
4# Commit frequently
5git commit -m "fix: button hover state"
6
7# Merge same day
8git checkout main
9git merge fix-button-styleFeature Flags#
// Ship incomplete features safely
if (featureFlags.isEnabled('new-checkout')) {
return <NewCheckout />;
}
return <LegacyCheckout />;Best For#
- Experienced teams
- High deployment frequency
- Feature flag infrastructure
Branch Naming Conventions#
1# Feature
2feature/add-user-authentication
3feature/JIRA-123-payment-integration
4
5# Bug fix
6fix/login-validation-error
7bugfix/cart-total-calculation
8
9# Hotfix
10hotfix/security-vulnerability
11hotfix/v1.2.1
12
13# Release
14release/1.2.0
15release/2024-q1
16
17# Chore/Maintenance
18chore/update-dependencies
19chore/refactor-api-clientCommit Message Conventions#
Conventional Commits#
1# Format: type(scope): description
2
3feat(auth): add OAuth2 login support
4fix(cart): correct total calculation with discounts
5docs(readme): update installation instructions
6refactor(api): simplify error handling
7test(users): add integration tests for signup
8chore(deps): update React to v19
9perf(images): implement lazy loading
10
11# Breaking changes
12feat(api)!: change response format for /users endpoint
13
14# With body and footer
15git commit -m "feat(payments): add Stripe integration
16
17Implements credit card payments using Stripe API.
18Includes webhook handling for payment events.
19
20Closes #123"Pull Request Best Practices#
PR Template#
1## Summary
2Brief description of changes
3
4## Changes
5- Added user authentication
6- Updated login form validation
7- Added password reset flow
8
9## Testing
10- [ ] Unit tests pass
11- [ ] Integration tests pass
12- [ ] Manual testing completed
13
14## Screenshots
15(if applicable)
16
17## Related Issues
18Closes #123Code Review Guidelines#
1# Good PR characteristics:
2- Single responsibility
3- < 400 lines changed
4- Clear description
5- Tests included
6- Self-reviewed first
7
8# Review checklist:
9- Does it solve the problem?
10- Is it tested?
11- Is it maintainable?
12- Are there security concerns?
13- Is documentation updated?Merge Strategies#
Merge Commit#
git merge --no-ff feature/login
# Preserves branch historySquash and Merge#
git merge --squash feature/login
git commit -m "feat: add login functionality"
# Clean linear historyRebase and Merge#
git rebase main
git checkout main
git merge feature/login --ff-only
# Linear history, individual commits preservedHandling Conflicts#
1# Update your branch
2git fetch origin
3git rebase origin/main
4
5# Resolve conflicts
6# Edit conflicted files
7git add .
8git rebase --continue
9
10# Or abort if needed
11git rebase --abortProtecting Main Branch#
1# GitHub branch protection rules:
2- Require pull request reviews
3- Require status checks to pass
4- Require branches to be up to date
5- Include administrators
6- Restrict force pushesConclusion#
Choose GitHub Flow for simplicity, GitFlow for structured releases, or trunk-based for rapid iteration. Consistent naming, clear commit messages, and good PR practices matter more than the specific workflow.