| name | git-workflow |
| description | Implement Git branching strategies, PR workflows, and release management patterns. Configure GitFlow, trunk-based development, or GitHub Flow for team collaboration. Use when establishing version control workflows or improving development team collaboration. |
| license | MIT |
| metadata | {"author":"devops-skills","version":"1.0"} |
Git Workflow
Implement effective branching strategies and pull request workflows for team collaboration.
When to Use This Skill
Use this skill when:
- Establishing team Git workflows
- Implementing branching strategies
- Configuring pull request processes
- Setting up release management
- Improving code review practices
Prerequisites
- Git installed
- Repository hosting (GitHub, GitLab, Bitbucket)
- Basic Git knowledge
Branching Strategies
Trunk-Based Development
Best for: Continuous deployment, small teams, mature CI/CD
main ─────●─────●─────●─────●─────●─────●─────●
│ │ │ │ │ │
└─● └─● └─● └─● └─● └─●
feature branches (short-lived)
git checkout main
git pull origin main
git checkout -b feature/add-login
git add .
git commit -m "feat: add login form"
git fetch origin
git rebase origin/main
git checkout main
git pull origin main
git merge feature/add-login
git push origin main
git branch -d feature/add-login
GitHub Flow
Best for: Continuous delivery, web applications
main ─────●─────●───────────●─────────────●─────●
│ ↑ ↑ ↑
└───●───●───┘ │ │
feature/login │ │
│ │
└───●───●───●───●───────┘ │
feature/dashboard │
│
└───●─────────────────────────┘
hotfix/security-patch
git checkout main
git pull origin main
git checkout -b feature/user-dashboard
git push -u origin feature/user-dashboard
GitFlow
Best for: Scheduled releases, versioned products
main ────────●────────────────●──────────────●
↑ ↑ ↑
release ────────┼────●───●──────┼──────────────┼
│ │ │ │ │
develop ───●────●────┼───●──●───●───●───●───●──┼
│ │ │ │ │ │
feature ───┴─────────┘ │ │ │ │
│ │ │ │
hotfix ────────────────────┴───────┼───┼──────┘
│ │
feature ────────────────────────────┴───┘
git flow init
git flow feature start user-auth
git flow feature finish user-auth
git flow release start 1.0.0
git flow release finish 1.0.0
git flow hotfix start security-fix
git flow hotfix finish security-fix
Commit Conventions
Conventional Commits
<type>(<scope>): <description>
[optional body]
[optional footer(s)]
Types:
feat: New feature
fix: Bug fix
docs: Documentation
style: Formatting
refactor: Code restructuring
test: Adding tests
chore: Maintenance
Examples:
git commit -m "feat(auth): add OAuth2 login support"
git commit -m "fix(api): handle null response from payment service"
git commit -m "docs: update API documentation for v2 endpoints"
git commit -m "refactor(db): optimize user query performance"
git commit -m "feat(api)!: change response format for user endpoint
BREAKING CHANGE: The user endpoint now returns an object instead of array"
Commit Message Template
git config --global commit.template ~/.gitmessage
Pull Request Workflow
PR Template
<!-- .github/pull_request_template.md -->
## Description
Brief description of changes
## Type of Change
- [ ] Bug fix (non-breaking change)
- [ ] New feature (non-breaking change)
- [ ] Breaking change
- [ ] Documentation update
## Testing
- [ ] Unit tests added/updated
- [ ] Integration tests added/updated
- [ ] Manual testing performed
## Checklist
- [ ] Code follows project style guidelines
- [ ] Self-review performed
- [ ] Documentation updated
- [ ] No new warnings introduced
## Related Issues
Closes #
## Screenshots (if applicable)
Branch Protection Rules
branch_protection:
branch: main
required_pull_request_reviews:
required_approving_review_count: 1
dismiss_stale_reviews: true
require_code_owner_reviews: true
required_status_checks:
strict: true
contexts:
- "ci/tests"
- "ci/lint"
restrictions:
users: []
teams: ["maintainers"]
enforce_admins: true
required_linear_history: true
allow_force_pushes: false
allow_deletions: false
Code Owners
# .github/CODEOWNERS
# Default owners
* @team-leads
# Frontend code
/src/frontend/ @frontend-team
*.tsx @frontend-team
*.css @frontend-team
# Backend code
/src/api/ @backend-team
/src/services/ @backend-team
# Infrastructure
/terraform/ @platform-team
/k8s/ @platform-team
Dockerfile @platform-team
# Documentation
/docs/ @tech-writers
*.md @tech-writers
Git Hooks
Pre-commit Hook
#!/bin/sh
npm run lint
if [ $? -ne 0 ]; then
echo "Linting failed. Fix errors before committing."
exit 1
fi
npm run test:unit
if [ $? -ne 0 ]; then
echo "Tests failed. Fix tests before committing."
exit 1
fi
if grep -r "console.log\|debugger\|binding.pry" --include="*.js" --include="*.ts" --include="*.rb" src/; then
echo "Remove debug statements before committing."
exit 1
fi
Using Husky
{
"husky": {
"hooks": {
"pre-commit": "lint-staged",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
},
"lint-staged": {
"*.{js,ts,tsx}": ["eslint --fix", "prettier --write"],
"*.{css,scss}": ["prettier --write"]
}
}
Commitlint Configuration
module.exports = {
extends: ['@commitlint/config-conventional'],
rules: {
'type-enum': [
2,
'always',
['feat', 'fix', 'docs', 'style', 'refactor', 'test', 'chore', 'revert']
],
'subject-max-length': [2, 'always', 72],
'body-max-line-length': [2, 'always', 100]
}
};
Release Workflow
Automated Release with Tags
git tag -a v1.0.0 -m "Release version 1.0.0"
git push origin v1.0.0
gh release create v1.0.0 \
--title "Release 1.0.0" \
--notes "Release notes here" \
--target main
Changelog Generation
npx conventional-changelog -p angular -i CHANGELOG.md -s
git cliff -o CHANGELOG.md
Common Git Operations
Rebase vs Merge
git checkout feature/my-feature
git rebase main
git push --force-with-lease
git checkout main
git merge feature/my-feature
git merge --squash feature/my-feature
git commit -m "feat: add feature X"
Cherry Pick
git cherry-pick abc123
git cherry-pick abc123..def456
git cherry-pick -n abc123
Interactive Rebase
git rebase -i HEAD~3
Common Issues
Issue: Merge Conflicts
Problem: Conflicts when merging branches
Solution: Rebase frequently, communicate with team, use smaller PRs
Issue: Diverged Branches
Problem: Local branch far behind remote
Solution: git pull --rebase or git fetch && git rebase origin/main
Issue: Accidental Commit to Wrong Branch
Problem: Committed to main instead of feature
Solution: git reset HEAD~1, checkout correct branch, recommit
Best Practices
- Keep branches short-lived (< 1 week)
- Write meaningful commit messages
- Use PR templates consistently
- Require code reviews
- Protect main/master branch
- Automate checks with CI
- Squash merge for clean history
- Delete branches after merge
Related Skills