Git Workflow Best Practices

Establish effective Git workflows for teams - branching strategies, commit conventions and code review

Git Workflow Best Practices

A consistent Git workflow improves collaboration and code quality.

Branch Strategy

main          ← Production (protected)
  │
  ├─ dev      ← Integration branch
  │    │
  │    ├─ feature/user-auth
  │    ├─ feature/api-v2
  │    └─ fix/login-bug
  │
  └─ hotfix/* ← Emergency fixes

Commit Messages

Follow conventional commits:

type(scope): description

[optional body]

[optional footer]

Types: - feat: New feature - fix: Bug fix - docs: Documentation - refactor: Code restructuring - test: Adding tests - chore: Maintenance

Example:

feat(auth): add OAuth2 login support

Implements Google and GitHub OAuth providers.
Adds token refresh mechanism.

Closes #123

Pull Request Process

  1. Create feature branch from dev
  2. Make small, focused commits
  3. Write descriptive PR title and body
  4. Request review from relevant team members
  5. Address feedback promptly
  6. Squash and merge when approved

Protection Rules

For main branch: - Require pull request reviews - Require status checks to pass - No force pushes - No deletions

Useful Commands

# Rebase feature branch on dev
git fetch origin
git rebase origin/dev

# Interactive rebase to clean commits
git rebase -i HEAD~5

# Cherry-pick specific commit
git cherry-pick abc123