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
- Create feature branch from
dev - Make small, focused commits
- Write descriptive PR title and body
- Request review from relevant team members
- Address feedback promptly
- 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