git:commit
npx skills add https://github.com/cblecker/claude-plugins --skill git:commit
Agent 安装分布
Skill 文档
Git Commit Creation
Enhance commit creation with mainline branch protection, commit style detection, and pre-commit verification steps.
Quick Reference
Workflow:
- â Check if on mainline (if yes, create branch first)
- â Verify changes exist (use dynamic context)
- â Detect commit style (detect-conventions skill)
- â Run pre-commit checks (CLAUDE.md verification)
- â Stage specific files (check for sensitive files, avoid
git add -A) - â Craft commit message (conventional commits if detected)
- â Create and verify commit
Commit message format:
- With conventional commits:
type(scope): description - Without:
Imperative description - Max 50 chars subject, 72 chars body
Commit types: feat, fix, docs, style, refactor, perf, test, chore, build, ci
Sections: Current Git State ⢠Core Workflow ⢠Conventional Commits ⢠Examples
Current Git State
- Current branch: !
git rev-parse --abbrev-ref HEAD - Mainline branch: !
${CLAUDE_PLUGIN_ROOT}/skills/commit/scripts/detect-mainline.sh - Status: !
git status --short - Staged changes: !
git diff --cached --stat - Recent commits: !
git log -5 --pretty=format:"%h %s"
Git Safety
Safety rules enforced by this skill:
- Never commit directly to mainline (redirect to branch creation)
- Check for sensitive files before staging
- Run pre-commit verification if specified
- Use specific file names rather than
git add -A
Core Workflow
Follow these steps when the user requests creating a commit:
1. Pre-Flight Checks
Check current branch:
Use the git state from dynamic context above to check if on mainline branch.
If on mainline branch:
- Warn user: “You’re on the
{mainline}branch. Creating a feature branch first is recommended.” - Invoke
/git:branchskill using the Skill tool - After branch created, continue with commit process
Verify there are changes to commit:
Use the git state from dynamic context above. Check the “Status” and “Staged changes” to see if there are any changes to commit.
If no changes exist:
Inform the user there’s nothing to commit and exit early.
2. Detect Commit Style
Invoke the detect-conventions skill to determine commit style (conventional commits or standard).
3. Run Pre-Commit Verification
Check CLAUDE.md for pre-commit steps:
Read project CLAUDE.md and look for sections like:
## Git Workflow
- Before committing, run: `npm test` and `npm run lint`
If CLAUDE.md specifies pre-commit steps:
- Execute each command specified
- Verify all pass successfully
- If any fail, report to user and ask how to proceed
- Do NOT commit if verification fails without user approval
Example:
# CLAUDE.md says: "Before committing, run: npm test"
npm test
if [ $? -ne 0 ]; then
# Tests failed - ask user before proceeding
fi
If pre-commit checks fail:
Present options to user:
- Fix the failing tests/checks
- Skip tests (not recommended)
- Commit anyway with
--no-verify(only if user explicitly approves)
4. Stage Files
Determine what to stage:
Prefer staging specific files by name rather than using git add -A or git add .:
- Safer (avoids accidentally staging sensitive files)
- More intentional
- Clearer what’s being committed
Check for sensitive files:
Warn before staging:
.env,.env.*files- Files with
credentials,secrets,passwordin name id_rsa,.pem,.keyfilesconfig.local.*files
Stage selected files:
git add file1.js file2.js file3.js
5. Craft Commit Message
Use results from the detect-conventions skill to determine commit message format.
Conventional Commits Reference
If conventional commits are used, follow this format: <type>(<scope>): <description>
| Type | Description |
|---|---|
| feat | New feature |
| fix | Bug fix |
| docs | Documentation |
| style | Code style (no logic change) |
| refactor | Code restructuring |
| perf | Performance improvement |
| test | Adding tests |
| chore | Maintenance |
| build | Build system changes |
| ci | CI/CD changes |
Subject: Imperative mood, lowercase, no period, max 50 chars
Example:
feat(auth): add OAuth2 login support
Implements OAuth2 authentication with Google and GitHub providers.
Includes token refresh and session management.
Closes #123
If conventional commits NOT used:
Use clear, descriptive messages:
- Start with imperative verb (Add, Fix, Update, Remove)
- Be specific about what changed
- Explain why if not obvious
Example:
Add user authentication with OAuth2
Allows users to log in with Google or GitHub accounts.
Message guidelines:
- Subject line: Max 50 characters, imperative mood, no period
- Body: Wrap at 72 characters, explain what and why
- Footer: Reference issues, breaking changes
6. Create Commit
Hand off to Claude’s built-in commit workflow:
At this point, let Claude’s default commit capabilities handle:
- Finalizing message
- Creating the commit
- Co-authored-by attribution
7. Verify Success
Report success to user with commit hash and message. If there was a problem, report the error.
Examples
Example 1: Commit on Main Branch (Redirects to Branch Creation)
User request: “Commit the authentication changes”
Steps:
- Pre-flight: On
mainbranch (is mainline) - Warn: “You’re on
main. Creating feature branch first.” - Invoke
/git:branchskill â Createsfeat/authentication - Continue on new branch, verify changes exist â
- Detect commit style: Conventional commits detected
- No pre-commit checks in CLAUDE.md
- Stage files:
git add src/auth.js src/auth.test.js - Craft message:
feat(auth): add user authentication - Create commit and verify
Example 2: Bug Fix with Pre-Commit Checks
User request: “Commit the login fix”
Steps:
- Pre-flight: On
fix/login-bug(not mainline) â, changes exist â - Detect commit style: Conventional commits detected
- Check CLAUDE.md: Says “run: npm test before committing”
- Run verification:
npm testâ Pass â - Stage:
git add src/login.js - Craft message:
fix(auth): resolve token expiry issue - Create commit and verify
Example 3: Simple Commit without Conventional Commits
User request: “Commit my changes”
Steps:
- Pre-flight: On
update-readme(not mainline) â, changes exist â - Detect commit style: No conventional commits
- No pre-commit checks in CLAUDE.md
- Stage:
git add README.md - Craft message:
Update installation instructions - Create commit and verify
Task Coordination
At workflow start:
- Create coordination task with TaskCreate:
- subject: “Create git commit”
- activeForm: “Creating git commit”
- metadata:
{ workflow: "commit", branch: "<current-branch>", startedAt: "<timestamp>" }
During workflow:
- Update task metadata as conventions are detected (from detect-conventions skill)
- Add metadata on errors or user decisions
At workflow end:
- Update task status to completed
- Add result metadata:
{ result: { commitSha: "<sha>", message: "<summary>" } }
Integration with Other Skills
This skill invokes:
/git:branch– When user tries to commit on mainline
This skill is invoked by:
/git:pr– When creating PR with uncommitted changes