Skill v1.2.0
currentAutomated scan100/10039 files
name: git-workflow description: Git best practices, branching strategies, commit conventions, and PR workflows. Use when reviewing git history, writing commits, setting up branching strategy, or improving git practices. Triggers on "git best practices", "commit message", "branching strategy", or "PR workflow". license: MIT metadata: author: AsyrafHussin version: "1.2.0"
Git Workflow
Git best practices, commit conventions, branching strategies, and pull request workflows. Guidelines for maintaining a clean, useful git history.
When to Apply
Reference these guidelines when:
- Writing commit messages
- Creating branches
- Setting up git workflows
- Reviewing pull requests
- Maintaining git history
Rule Categories by Priority
| Priority | Category | Impact | Prefix | |
|---|---|---|---|---|
| 1 | Commit Messages | CRITICAL | commit- | |
| 2 | Branching Strategy | HIGH | branch- | |
| 3 | Pull Requests | HIGH | pr- | |
| 4 | History Management | MEDIUM | history- | |
| 5 | Collaboration | MEDIUM | collab- |
Quick Reference
1. Commit Messages (CRITICAL)
commit-conventional- Use conventional commitscommit-atomic- Atomic commits (one logical change)commit-present-tense- Use imperative present tensecommit-meaningful- Descriptive, meaningful messagescommit-body- Add body for complex changescommit-references- Reference issues/ticketscommit-git-hooks- Enforce standards with Husky + commitlint
2. Branching Strategy (HIGH)
branch-naming- Consistent branch namingbranch-feature- Feature branch workflowbranch-main-protected- Protect main branchbranch-short-lived- Keep branches short-livedbranch-delete-merged- Delete merged branchesbranch-release- Release branch strategybranch-workflow-strategies- GitFlow vs GitHub Flow vs Trunk-Basedbranch-monorepo- Monorepo git workflows
3. Pull Requests (HIGH)
pr-small- Keep PRs small and focusedpr-description- Write clear descriptionspr-reviewers- Request appropriate reviewerspr-ci-pass- Ensure CI passespr-squash- Squash when appropriatepr-draft- Use draft PRs for WIP and early feedback
4. History Management (MEDIUM)
history-rebase- Rebase vs mergehistory-no-force-push- Avoid force push to shared brancheshistory-clean- Keep history cleanhistory-tags- Use tags for releaseshistory-worktree- Work on multiple branches with git worktree
5. Collaboration (MEDIUM)
collab-code-review- Effective code reviewscollab-conflicts- Handle merge conflictscollab-communication- Communicate changescollab-gitignore- .gitignore best practices
Essential Guidelines
Conventional Commits
# Format<type>(<scope>): <subject><body><footer>
Types
| Type | Description | |
|---|---|---|
feat | New feature | |
fix | Bug fix | |
docs | Documentation only | |
style | Formatting, no code change | |
refactor | Code change, no feature/fix | |
perf | Performance improvement | |
test | Adding/updating tests | |
chore | Maintenance, dependencies | |
ci | CI/CD changes | |
build | Build system changes | |
revert | Revert previous commit |
Examples
# ✅ Good commit messagesfeat(auth): add password reset functionalityfix(cart): resolve quantity update race conditiondocs(readme): add installation instructionsrefactor(api): extract validation into middlewaretest(user): add unit tests for registrationchore(deps): update dependencies to latest versions# With body and footerfeat(orders): implement order cancellationAdd ability for users to cancel pending orders within 24 hours.Cancelled orders trigger refund process automatically.Closes #123BREAKING CHANGE: Order status enum now includes 'cancelled'# ❌ Bad commit messagesfix bugupdateWIPasdfasdfchangesmisc fixes
Branch Naming
# ✅ Good branch namesfeature/user-authenticationfeature/JIRA-123-password-resetfix/cart-total-calculationfix/issue-456-login-redirecthotfix/security-patchdocs/api-documentationrefactor/database-querieschore/update-dependencies# ❌ Bad branch namesnew-featurejohn-branchtestfixtempasdf
Branch Workflow
# Main branchesmain # Production-ready codedevelop # Integration branch (optional)# Supporting branchesfeature/* # New featuresfix/* # Bug fixeshotfix/* # Production hotfixesrelease/* # Release preparation# Workflowgit checkout maingit pull origin maingit checkout -b feature/user-profile# Work on feature...git add .git commit -m "feat(profile): add profile page"# Keep branch updatedgit fetch origingit rebase origin/main# Push and create PRgit push -u origin feature/user-profile
Atomic Commits
# ❌ One commit doing multiple thingsgit commit -m "Add login, fix header, update deps"# ✅ Separate commits for each changegit commit -m "feat(auth): add login page"git commit -m "fix(header): correct navigation alignment"git commit -m "chore(deps): update React to v18.2"
Commit Frequently, Push Regularly
# ✅ Small, frequent commitsgit commit -m "feat(cart): add product to cart"git commit -m "feat(cart): display cart item count"git commit -m "feat(cart): implement remove item"git commit -m "test(cart): add unit tests"# ❌ One massive commitgit commit -m "feat: implement entire shopping cart"
Pull Request Best Practices
PR Title
# Format (like commit)<type>(<scope>): <description># ✅ Good PR titlesfeat(auth): implement OAuth2 loginfix(checkout): resolve payment processing errordocs(api): add endpoint documentation# ❌ Bad PR titlesUpdateFix stuffWIP
PR Description Template
## SummaryBrief description of what this PR does.## Changes-Added user authentication endpoints-Implemented JWT token generation-Added password hashing with bcrypt## Testing-[ ] Unit tests pass-[ ] Integration tests pass-[ ] Manual testing completed## Screenshots (if UI changes)[Add screenshots here]## Related IssuesCloses #123Related to #456## Checklist-[ ] Code follows project conventions-[ ] Self-review completed-[ ] Tests added/updated-[ ] Documentation updated
Keep PRs Small
# ✅ Focused PRsPR #1: Add user model and migrationsPR #2: Implement user registration endpointPR #3: Add email verificationPR #4: Implement login/logout# ❌ Large unfocused PRPR #1: Add entire user authentication system(2000+ lines, 50+ files)
Rebase vs Merge
# ✅ Rebase for feature branches (clean history)git checkout feature/my-featuregit fetch origingit rebase origin/main# Resolve any conflictsgit push --force-with-lease # Only your branch!# ✅ Merge for integrating to main (preserve context)git checkout maingit merge --no-ff feature/my-feature# Creates merge commit, preserves branch history# ❌ Never force push to shared branchesgit push --force origin main # NEVER DO THIS
Interactive Rebase (Clean Up)
# Before pushing, clean up commitsgit rebase -i HEAD~5# In editor:pick abc123 feat: add login pagesquash def456 fix typosquash ghi789 more fixespick jkl012 feat: add logout# Result: clean history with meaningful commits
Handling Conflicts
# During rebasegit rebase origin/main# CONFLICT in file.ts# 1. Open conflicted files# 2. Resolve conflicts (remove markers)# 3. Stage resolved filesgit add file.ts# 4. Continue rebasegit rebase --continue# Or abort if neededgit rebase --abort
Git Hooks
# .husky/pre-commit#!/bin/shnpm run lintnpm run test:unit# .husky/commit-msg#!/bin/shnpx commitlint --edit $1# commitlint.config.jsmodule.exports = {extends: ['@commitlint/config-conventional'],};
Tagging Releases
# Semantic versioning tagsgit tag -a v1.0.0 -m "Release version 1.0.0"git push origin v1.0.0# List tagsgit tag -l "v1.*"# Tag formatv1.0.0 # Major.Minor.Patchv1.0.0-beta.1 # Pre-releasev1.0.0-rc.1 # Release candidate
.gitignore Best Practices
# Dependenciesnode_modules/vendor/# Build outputsdist/build/.next/# Environment files.env.env.local.env.*.local# IDE.idea/.vscode/*.swp# OS files.DS_StoreThumbs.db# Logs*.loglogs/# Test coveragecoverage/# Cache.cache/*.cache
Useful Git Commands
# View commit historygit log --oneline --graph --all# See what changedgit diff --stagedgit diff HEAD~1# Undo last commit (keep changes)git reset --soft HEAD~1# Discard local changesgit checkout -- file.tsgit restore file.ts # Git 2.23+# Stash changesgit stashgit stash popgit stash list# Cherry-pick commitgit cherry-pick abc123# Find who changed a linegit blame file.ts# Search commitsgit log --grep="fix"git log -S "functionName"
Output Format
When reviewing git practices, output findings:
[category] Description of issue or suggestion
Example:
[commit] Use imperative mood: "Add feature" not "Added feature"[branch] Branch name 'test' should follow pattern: feature/description[pr] PR is too large (50+ files), consider splitting
How to Use
Read individual rule files for detailed explanations:
rules/commit-conventional-format.mdrules/branch-naming-convention.mdrules/pr-small-focused.md
References
- Git Official Documentation - Comprehensive Git documentation
- Pro Git Book - The complete Pro Git book
- Conventional Commits - Commit message specification
- GitHub Flow - Lightweight workflow
- How to Write a Git Commit Message - Commit message guide
- Google Code Review Practices - Code review best practices
Examples from Well-Known Projects
Learn from projects with excellent git practices:
- Linux Kernel - Detailed commit messages and patch workflow
- React - Conventional commits and thorough PR reviews
- Vue.js - Clean commit history and good PR templates
- TypeScript - Structured branching and clear release process
- Next.js - Conventional commits and automated releases
Configuration Examples
Commitlint
// commitlint.config.jsmodule.exports = {extends: ['@commitlint/config-conventional'],rules: {'type-enum': [2,'always',['feat', 'fix', 'docs', 'style', 'refactor', 'perf', 'test', 'chore', 'ci', 'build', 'revert']],'subject-max-length': [2, 'always', 72],'body-max-line-length': [2, 'always', 100]}};
Husky Git Hooks
# .husky/commit-msg#!/bin/shnpx commitlint --edit $1# .husky/pre-commit#!/bin/shnpm run lintnpm test
GitHub PR Template
# .github/PULL_REQUEST_TEMPLATE.md## SummaryBrief description of changes## Changes-List key changes-One per line## Testing-[ ] Unit tests pass-[ ] Integration tests pass-[ ] Manual testing completed## RelatedCloses #issue-number
Metadata
Skill Version: 1.2.0 Last Updated: 2026-03-08 Total Rules: 31 Categories: 5 (Commit Messages, Branching Strategy, Pull Requests, History Management, Collaboration)
Compatible With:
- Git 2.0+
- GitHub, GitLab, Bitbucket, Azure DevOps
Recommended Tools:
- Git - Version control system
- GitHub CLI - GitHub command-line tool
- Commitlint - Commit message linter
- Husky - Git hooks
- Semantic Release - Automated versioning
License
MIT License. This skill is provided as-is for educational and development purposes.