Introduction
A consistent Git workflow helps teams collaborate effectively, avoid conflicts, and maintain a clean project history.
Branch Strategy
A simple and effective branching model:
main— production-ready code, always deployabledevelop— integration branch for featuresfeature/*— individual feature brancheshotfix/*— urgent production fixes
Feature Branch Workflow
# Create feature branch from develop
git checkout develop
git pull origin develop
git checkout -b feature/user-auth
# Work on your feature, commit regularly
git add -A
git commit -m "Add login form and validation"
# Keep up to date with develop
git fetch origin
git rebase origin/develop
# Push and create pull request
git push -u origin feature/user-authCommit Message Convention
Use conventional commits for clear history:
feat: add user registration endpoint
fix: resolve password reset token expiry
docs: update API documentation
refactor: extract email service into separate class
test: add unit tests for payment module
chore: update dependenciesPull Request Guidelines
- Keep PRs small and focused (under 400 lines changed)
- Write a clear description of what and why
- Request reviews from relevant team members
- Ensure CI passes before merging
- Squash merge for clean history, or rebase merge for detailed history
Protecting main
- Require pull request reviews before merging
- Require CI checks to pass
- Disable force pushes to main
- Enable branch protection rules in your Git hosting platform