| name | git-commit |
| description | Create logically grouped, atomic git commits with well-formatted commit messages following best practices. Use this skill when you need to commit changes to a git repository with proper message formatting and atomic grouping. |
| allowed-tools | Bash, Read, Edit |
Git Commit Skill
This skill helps you create well-structured, atomic git commits with properly formatted commit messages.
When to Use This Skill
Use this skill when:
- You need to commit changes to a git repository
- You want to create atomic, logically grouped commits
- You need to follow commit message best practices
- You have multiple changes that should be split into separate commits
- You need to use git partial adds (git add -p) for fine-grained control
Task Overview
Based on the current git status and changes, create a set of logically grouped, atomic commits. Be specific with each grouping, and keep scope minimal. Leverage partial adds to make sure that multiple changes within a single file aren't batched into commits with unrelated changes.
Process
Analyze Current State
- Check git status to see staged and unstaged changes
- Review git diff to understand what has changed
- Check recent commits (
git log --oneline -20) to understand:- Whether the project uses conventional commits (e.g.,
feat:,fix:,docs:) - The project's commit message style and conventions
- Typical subject line length and formatting patterns
- Whether the project uses conventional commits (e.g.,
Group Changes Logically
- Identify related changes that should be committed together
- Separate unrelated changes into different commits
- Use
git add -pfor partial adds when a file contains multiple logical changes
Create Commits
- Stage the appropriate changes for each commit
- Write commit messages following the best practices below
- Verify each commit is atomic and complete
Commit Message Format Detection
IMPORTANT: Before writing any commits, analyze the recent git history to determine the project's commit style:
- Check for Conventional Commits: Look for patterns like
feat:,fix:,docs:,chore:,refactor:,test:,style:,perf:,ci:,build: - Match the existing style: If 80% or more of recent commits follow conventional commits, use that format
- Be consistent: Match the capitalization, punctuation, and structure of existing commits
Conventional Commits Format
If the project uses conventional commits, follow this structure:
<type>[(optional scope)]: <description>
[optional body]
[optional footer(s)]
Common types:
feat: A new featurefix: A bug fixdocs: Documentation changesstyle: Code style changes (formatting, missing semicolons, etc.)refactor: Code changes that neither fix bugs nor add featuresperf: Performance improvementstest: Adding or updating testsbuild: Changes to build system or dependenciesci: Changes to CI configurationchore: Other changes that don't modify src or test files
Examples:
feat: add user authenticationfix: resolve null pointer in login handlerdocs: update API documentationrefactor(auth): simplify token validation logic
Git Commit Message Best Practices
Follow these seven rules for excellent commit messages (adjust for conventional commits if used):
- Separate subject from body with a blank line - Critical for readability
- Limit subject line to 50 characters - Forces concise summaries
- Capitalize the subject line - Consistent formatting
- Do not end subject line with a period - It's a title, not a sentence
- Use imperative mood in subject - "Add feature" not "Added feature"
- Test: Subject should complete "If applied, this commit will _____"
- Wrap body at 72 characters - Ensures readability in terminals
- Use body to explain what and why vs. how - Code shows how, commit explains why
Message Structure
<subject: concise summary, imperative, capitalized, no period>
<body: explain the motivation for the change and contrast with previous behavior>
<footer: references to issues, breaking changes, etc.>
Key Principles
- Atomic commits: Each commit should represent one logical change
- Context is king: Explain WHY the change was made, not just what
- Future-proof: Write for someone (including future you) reading this months later
- Consistency: Maintain uniform style across the project
Examples
Good Examples (Traditional Style):
Refactor subsystem X for readabilityRemove deprecated methods from UserServiceFix null pointer exception in login handlerAdd user authentication middleware
Good Examples (Conventional Commits):
feat: add user authentication middlewarefix: resolve null pointer exception in login handlerrefactor: improve subsystem X readabilitychore: remove deprecated methods from UserService
Bad Examples:
fixed stuffChangeswipUpdate file.jsfeat added new feature(incorrect format - missing colon)
Implementation Steps
- Run
git statusto see current state - Run
git diff HEADto see all changes - Run
git log --oneline -20to analyze recent commit style- Determine if conventional commits are used (look for
type:prefix patterns) - Note the typical capitalization and formatting style
- Identify any project-specific conventions
- Determine if conventional commits are used (look for
- Identify logical groupings of changes
- For each logical group:
- Stage the relevant changes (use
git add -pif needed) - Create a commit with a well-formatted message matching the project's style
- Verify the commit with
git show
- Stage the relevant changes (use
- After all commits, run
git statusto verify nothing important was missed
Notes
- ALWAYS check recent git history first to determine if conventional commits are used
- Match the project's existing style - consistency is more important than personal preference
- DO NOT push to remote unless explicitly asked
- Always verify authorship and commit details before amending
- Use
git add -pfor interactive staging when files contain multiple unrelated changes - Keep commits focused and atomic - one logical change per commit
- If in doubt about whether to use conventional commits, look at the last 20-30 commits for patterns