| name | git-commit |
| description | Stage, commit, and push changes with meaningful commit messages following conventional commits. Use when you need to commit code changes, create atomic commits, or push to remote. Analyzes diffs to generate descriptive messages. |
Git Commit Workflow
When to Use This Skill
Use this skill when:
- You've completed a feature, bug fix, or refactor
- You need to commit changes with a meaningful message
- You want to create atomic commits (one logical change per commit)
- You need to push changes to a remote repository
Workflow Steps
Step 1: Analyze Current State
First, understand what has changed:
git status
git diff
git diff --cached
git diff --stat
Step 2: Detect Branch Name Prefix
Before committing, extract the current branch name and check if it matches the MYK-<digits> pattern:
BRANCH=$(git rev-parse --abbrev-ref HEAD)
TICKET=$(echo "$BRANCH" | grep -oE 'MYK-[0-9]+' | head -1)
- If
TICKET is non-empty (e.g., MYK-12345), prefix every commit message with MYK-12345:
- If the branch does not contain a
MYK-<digits> pattern, do not add any prefix
Step 3: Group Changes Logically
Review changes and group them into logical commits. Each commit should:
- Represent ONE logical change
- Be self-contained and not break the build
- Have a clear purpose
Common groupings:
- Feature implementation (may span multiple files)
- Bug fix (typically focused)
- Refactoring (renaming, restructuring)
- Documentation updates
- Test additions
- Configuration changes
- Dependency updates
Step 4: Stage Files Appropriately
git add path/to/file.py path/to/another.py
git add src/feature/
git add -p path/to/file.py
git add -u
git add -A
Step 5: Write Meaningful Commit Message
Follow the Conventional Commits format, prefixed with the branch ticket ID when applicable:
When branch matches MYK-<digits> (e.g., branch MYK-16256-jwt-refresh):
MYK-16256: <type>(<scope>): <short description>
<optional body - explain WHY, not what>
<optional footer - breaking changes, issue refs>
When branch does NOT match (e.g., branch main, feature/add-logging):
<type>(<scope>): <short description>
<optional body - explain WHY, not what>
<optional footer - breaking changes, issue refs>
Types:
| Type | Description |
|---|
feat | New feature |
fix | Bug fix |
docs | Documentation only |
style | Formatting, no code change |
refactor | Code restructuring, no behavior change |
perf | Performance improvement |
test | Adding/fixing tests |
build | Build system, dependencies |
ci | CI/CD configuration |
chore | Maintenance tasks |
Examples (branch contains MYK ticket):
git commit -m "MYK-16256: feat(auth): add JWT refresh token support"
git commit -m "MYK-16171: fix(api): handle null response from external service
The third-party API occasionally returns null instead of an empty array.
Added null check to prevent TypeError in downstream processing."
git commit -m "MYK-67656: feat(db)!: migrate from MongoDB to PostgreSQL
BREAKING CHANGE: Database connection string format has changed.
Update MONGODB_URI to POSTGRES_URI in environment configuration."
git commit -m "MYK-17909: fix(worker): prevent duplicate job processing
Closes #123"
Examples (branch does NOT contain MYK ticket):
git commit -m "feat(auth): add JWT refresh token support"
git commit -m "fix(api): handle null response from external service
The third-party API occasionally returns null instead of an empty array.
Added null check to prevent TypeError in downstream processing."
git commit -m "chore(config): update database connection string format"
Step 6: Push to Remote
git push origin HEAD
git push -u origin feature-branch
git push --force-with-lease origin feature-branch
Generating Commit Messages from Diffs
When analyzing changes to generate a commit message:
- Run
git rev-parse --abbrev-ref HEAD and extract MYK-<digits> if present
- Run
git diff --cached (or git diff for unstaged)
- Identify the primary change type (feat, fix, refactor, etc.)
- Determine the scope from file paths (api, worker, db, etc.)
- Summarize the change in imperative mood ("add", "fix", "update")
- Prefix with ticket ID if branch matches
MYK-<digits>
- Add context in body if the "why" isn't obvious
Analyzing Diff Patterns
| Diff Pattern | Likely Type | Message Hint |
|---|
| New file added | feat or test | "add X" |
| File deleted | refactor or chore | "remove X" |
| Function renamed | refactor | "rename X to Y" |
| Error handling added | fix or feat | "handle X error case" |
| Import changes only | refactor | "reorganize imports" |
| Comment changes | docs | "document X behavior" |
| Config value changed | chore or fix | "update X configuration" |
| Test file changed | test | "improve X test coverage" |
Multi-Commit Workflow
When changes span multiple logical units:
git add src/models/user.py src/schemas/user.py
git commit -m "MYK-20100: feat(user): add email verification fields"
git add src/services/email.py
git commit -m "MYK-20100: feat(email): implement verification email sender"
git add tests/test_user.py tests/test_email.py
git commit -m "MYK-20100: test(user): add email verification tests"
git push origin HEAD
Interactive Staging with git add -p
For fine-grained control over what goes into a commit:
git add -p
Pre-Push Checklist
Before pushing, verify:
- [ ] All tests pass locally
- [ ] Code is formatted (run linter/formatter)
- [ ] No debug code or console.logs left
- [ ] Commit messages are meaningful
- [ ] No sensitive data (keys, passwords) in commits
- [ ] Branch is up to date with main (rebase if needed)
Common Scenarios
Scenario 1: Single Feature Commit (MYK branch)
git status
git diff
git add -A
git commit -m "MYK-18432: feat(transcription): add language detection support"
git push origin HEAD
Scenario 2: Fix with Related Test (MYK branch)
git add src/services/parser.py
git commit -m "MYK-19001: fix(parser): handle empty input gracefully"
git add tests/test_parser.py
git commit -m "MYK-19001: test(parser): add empty input test cases"
git push origin HEAD
Scenario 3: Single Feature Commit (non-MYK branch)
git status
git diff
git add -A
git commit -m "feat(transcription): add language detection support"
git push origin HEAD
Scenario 4: Amend Last Commit
git add forgotten_file.py
git commit --amend --no-edit
git commit --amend -m "MYK-16256: feat(api): better description here"
Scenario 5: Interactive Rebase Before Push
git rebase -i HEAD~3
Scope Detection from File Paths
| Path Pattern | Suggested Scope |
|---|
src/api/ | api |
src/services/ | Service name (e.g., transcription) |
src/models/ or src/db/ | db |
src/utils/ | utils or utility name |
tests/ | test (or the tested module) |
config/ or .env | config |
docker-compose*, Dockerfile | docker |
k8s/, kubernetes/ | k8s |
docs/, *.md | docs |
pyproject.toml, package.json | deps or build |
.github/, .gitlab-ci* | ci |
Tips for Better Commits
- Commit early, commit often - Small commits are easier to review and revert
- One thing per commit - Don't mix features with refactoring
- Write for future you - Explain why, not just what
- Use imperative mood - "add feature" not "added feature"
- Reference issues - Link to tickets with
Closes #123 or Refs #456
- Don't commit generated files - Use
.gitignore
- Review before committing - Use
git diff --cached to double-check