Skip to main content

Git Workflow & Branching Strategy

Overview

Branch Structure

Main Branches

  • main: Production-ready code
  • develop: Integration branch for features

Supporting Branches

  • feature/: New features and enhancements
  • bugfix/: Non-critical bug fixes
  • hotfix/: Critical production fixes
  • release/: Release preparation

Branch Naming Convention

<type>/<ticket-number>-<description>

Examples:
feature/OAN-123-add-payment-gateway
hotfix/OAN-456-fix-auth-issue
release/1.2.0

Development Workflow

Commit Message Format

<type>(<scope>): <subject>

<body>

<footer>

Types

  • feat: New feature
  • fix: Bug fix
  • docs: Documentation
  • style: Formatting
  • refactor: Code restructuring
  • test: Test cases
  • chore: Maintenance

Example

feat(payment): implement RiyadBank integration

- Add payment gateway service
- Implement transaction handling
- Add error handling

Closes OAN-123

Code Review Process

Review Checklist

  1. Code Quality

    • Follows coding standards
    • Proper error handling
    • Adequate test coverage
  2. Security

    • No sensitive data exposed
    • Proper input validation
    • Secure API handling
  3. Performance

    • Efficient algorithms
    • Proper caching
    • Resource optimization

Release Process

Common Commands

Branch Management

# Create feature branch
git checkout -b feature/OAN-123 develop

# Update from develop
git checkout develop
git pull
git checkout feature/OAN-123
git rebase develop

# Clean up after merge
git branch -d feature/OAN-123

Code Review

# Before creating PR
git fetch origin
git rebase origin/develop
git push origin feature/OAN-123

# Update PR after review
git add .
git commit --amend
git push -f origin feature/OAN-123

Release Management

# Create release
git checkout -b release/1.0.0 develop
git tag -a v1.0.0 -m "Version 1.0.0"
git push origin v1.0.0

# Hotfix
git checkout -b hotfix/1.0.1 main

Best Practices

Branch Management

  • Keep branches short-lived
  • Regular rebasing with parent branch
  • Delete branches after merging
  • Protect main branches

Commits

  • Write clear commit messages
  • Make atomic commits
  • Reference ticket numbers
  • Squash before merging

Code Review

  • Review in small batches
  • Provide constructive feedback
  • Focus on code, not coder
  • Use review checklists

Troubleshooting

Common Issues

  1. Merge Conflicts

    git checkout develop
    git pull
    git checkout feature/OAN-123
    git rebase develop
    # Resolve conflicts
    git rebase --continue
  2. Wrong Branch

    git stash
    git checkout correct-branch
    git stash pop
  3. Bad Commit

    # Revert last commit
    git revert HEAD

    # Reset to specific commit
    git reset --hard commit-hash