Workflows
Quick reference for common Git workflows and branching strategies.
Git Flow
Setup
# Initialize git flow
git flow init
# Or manually create branches
git checkout -b develop
git push -u origin develop
Feature Development
# Start feature
git flow feature start feature-name
# Or manually:
git checkout -b feature/feature-name develop
# Work on feature
git add .
git commit -m "Add feature functionality"
# Finish feature
git flow feature finish feature-name
# Or manually:
git checkout develop
git merge feature/feature-name
git branch -d feature/feature-name
Release Management
# Start release
git flow release start 1.0.0
# Or manually:
git checkout -b release/1.0.0 develop
# Finish release
git flow release finish 1.0.0
# Or manually:
git checkout main
git merge release/1.0.0
git tag -a 1.0.0 -m "Release 1.0.0"
git checkout develop
git merge release/1.0.0
git branch -d release/1.0.0
Hotfix Process
# Start hotfix
git flow hotfix start hotfix-name
# Or manually:
git checkout -b hotfix/hotfix-name main
# Finish hotfix
git flow hotfix finish hotfix-name
# Or manually:
git checkout main
git merge hotfix/hotfix-name
git tag -a 1.0.1 -m "Hotfix 1.0.1"
git checkout develop
git merge hotfix/hotfix-name
git branch -d hotfix/hotfix-name
GitHub Flow
Simple Feature Development
# Create feature branch
git checkout -b feature/new-feature
# Work and commit
git add .
git commit -m "Add new feature"
git push -u origin feature/new-feature
# Create pull request on GitHub
# After review and approval, merge via GitHub
# Clean up locally
git checkout main
git pull origin main
git branch -d feature/new-feature
Hotfix in GitHub Flow
# Create hotfix branch from main
git checkout main
git pull origin main
git checkout -b hotfix/urgent-fix
# Fix and commit
git add .
git commit -m "Fix urgent issue"
git push -u origin hotfix/urgent-fix
# Create pull request
# After approval, merge via GitHub
# Clean up
git checkout main
git pull origin main
git branch -d hotfix/urgent-fix
Forking Workflow
Initial Setup
# Fork repository on GitHub
# Clone your fork
git clone https://github.com/your-username/project.git
cd project
# Add upstream remote
git remote add upstream https://github.com/original-owner/project.git
git remote -v
Staying in Sync
# Fetch upstream changes
git fetch upstream
# Merge upstream changes
git checkout main
git merge upstream/main
# Push to your fork
git push origin main
Contributing Changes
# Create feature branch
git checkout -b feature/contribution
# Work and commit
git add .
git commit -m "Add contribution"
# Push to your fork
git push -u origin feature/contribution
# Create pull request from your fork to upstream
# After merge, sync your fork
git checkout main
git pull upstream main
git push origin main
git branch -d feature/contribution
Centralized Workflow
Daily Workflow
# Start day - get latest changes
git pull origin main
# Work on feature
git add .
git commit -m "Add feature"
# Before pushing, ensure you're up to date
git pull origin main
# Resolve conflicts if any
git add .
git commit -m "Resolve merge conflicts"
# Push changes
git push origin main
Handling Conflicts
# Pull latest changes
git pull origin main
# If conflicts, resolve them
# Edit conflicted files
git add .
git commit -m "Resolve conflicts"
# Push resolved changes
git push origin main
Feature Branch Workflow
Team Development
# Create feature branch
git checkout -b feature/user-authentication
# Work on feature
git add .
git commit -m "Implement user login"
git push -u origin feature/user-authentication
# Regular sync with main
git checkout main
git pull origin main
git checkout feature/user-authentication
git merge main # or git rebase main
# Push updates
git push origin feature/user-authentication
# When ready, create pull request
# After review, merge to main
Code Review Process
# Create feature branch
git checkout -b feature/code-review
# Work and commit
git add .
git commit -m "Implement feature"
# Push for review
git push -u origin feature/code-review
# Address review comments
git add .
git commit -m "Address review comments"
git push origin feature/code-review
# After approval, merge
git checkout main
git pull origin main
git merge feature/code-review
git push origin main
git branch -d feature/code-review
Release Workflows
Semantic Versioning
# Major version (breaking changes)
git tag -a v2.0.0 -m "Release v2.0.0 - Breaking changes"
# Minor version (new features)
git tag -a v1.1.0 -m "Release v1.1.0 - New features"
# Patch version (bug fixes)
git tag -a v1.0.1 -m "Release v1.0.1 - Bug fixes"
# Push tags
git push --tags
Release Branch Strategy
# Create release branch
git checkout -b release/1.0.0 develop
# Final testing and bug fixes
git add .
git commit -m "Fix release issues"
# Merge to main
git checkout main
git merge release/1.0.0
git tag -a 1.0.0 -m "Release 1.0.0"
# Merge back to develop
git checkout develop
git merge release/1.0.0
# Clean up
git branch -d release/1.0.0
git push origin main develop --tags
CI/CD Integration
GitHub Actions Integration
# Create feature branch
git checkout -b feature/ci-integration
# Work and commit
git add .
git commit -m "Add CI configuration"
# Push triggers CI
git push -u origin feature/ci-integration
# CI runs tests automatically
# After CI passes and review, merge
Pre-commit Hooks
# Install pre-commit hooks
pre-commit install
# Commit triggers hooks
git commit -m "Add new feature"
# Hooks run automatically
# If hooks fail, fix issues
git add .
git commit -m "Fix linting issues"
Emergency Workflows
Hotfix Deployment
# Create hotfix branch
git checkout main
git pull origin main
git checkout -b hotfix/security-fix
# Fix critical issue
git add .
git commit -m "Fix security vulnerability"
# Test thoroughly
git push -u origin hotfix/security-fix
# Fast-track review and merge
git checkout main
git merge hotfix/security-fix
git tag -a 1.0.1 -m "Security hotfix 1.0.1"
git push origin main --tags
# Deploy immediately
# Merge back to develop
git checkout develop
git merge hotfix/security-fix
git push origin develop
Rollback Strategy
# Identify problematic commit
git log --oneline
# Create rollback branch
git checkout -b rollback/revert-bad-commit
# Revert the commit
git revert <bad-commit-hash>
# Push rollback
git push -u origin rollback/revert-bad-commit
# Fast-track merge
git checkout main
git merge rollback/revert-bad-commit
git push origin main
Best Practices
Commit Messages
# Good commit messages
git commit -m "Add user authentication feature"
git commit -m "Fix login validation bug"
git commit -m "Update documentation for API changes"
# Follow conventional commits
git commit -m "feat: add user authentication"
git commit -m "fix: resolve login validation issue"
git commit -m "docs: update API documentation"
Branch Naming
# Good branch names
git checkout -b feature/user-auth
git checkout -b bugfix/login-error
git checkout -b hotfix/security-patch
git checkout -b release/v1.2.0
# Team prefixes
git checkout -b john/feature/user-auth
git checkout -b jane/bugfix/login-error
Regular Maintenance
# Clean up merged branches
git branch --merged main | grep -v main | xargs -n 1 git branch -d
# Update main regularly
git checkout main
git pull origin main
# Sync develop with main
git checkout develop
git merge main
git push origin develop