| created | "2025-12-16T00:00:00.000Z" |
| modified | "2025-12-16T00:00:00.000Z" |
| reviewed | "2025-12-16T00:00:00.000Z" |
| name | git-commit-workflow |
| description | Commit message conventions, staging practices, and commit best practices.
Covers conventional commits, explicit staging workflow, logical change grouping,
and humble fact-based communication style.
Use when user mentions committing changes, writing commit messages, git add,
git commit, staging files, or conventional commit format.
|
| allowed-tools | Bash, Read |
Git Commit Workflow
Expert guidance for commit message conventions, staging practices, and commit best practices using conventional commits and explicit staging workflows.
Core Expertise
- Conventional Commits: Standardized format for automation and clarity
- Explicit Staging: Always stage files individually with clear visibility
- Logical Grouping: Group related changes into focused commits
- Communication Style: Humble, factual, concise commit messages
- Pre-commit Integration: Run checks before committing
Note: Commits are made on main branch and pushed to remote feature branches for PRs. See git-branch-pr-workflow skill for the main-branch development pattern.
Conventional Commit Format
Standard Format
type(scope): description
[optional body]
[optional footer(s)]
Commit Types
- feat: New feature for the user
- fix: Bug fix for the user
- docs: Documentation changes
- style: Formatting, missing semicolons, etc (no code change)
- refactor: Code restructuring without changing behavior
- test: Adding or updating tests
- chore: Maintenance tasks, dependency updates, linter fixes
- perf: Performance improvements
- ci: CI/CD changes
Examples
git commit -m "feat(auth): implement OAuth2 integration"
git commit -m "fix(api): resolve null pointer in user service
Fixed race condition where user object could be null during
concurrent authentication requests."
git commit -m "docs(readme): update installation instructions"
git commit -m "feat(api)!: migrate to GraphQL endpoints
BREAKING CHANGE: REST endpoints removed in favor of GraphQL.
See migration guide at docs/migration.md"
git commit -m "fix(auth): resolve login validation issues
- Handle empty email addresses
- Validate password strength requirements
- Add rate limiting to prevent brute force
Fixes #123, #124"
Commit Message Best Practices
DO:
- Use imperative mood ("add feature" not "added feature")
- Keep first line under 72 characters
- Be concise and factual
- ALWAYS reference related issues - every commit should link to relevant issues
- Use GitHub closing keywords:
Fixes #123, Closes #456, Resolves #789
- Use
Refs #N for related issues that shouldn't auto-close
- Use lowercase for type and scope
- Be humble and modest
DON'T:
- Use past tense ("added" or "fixed")
- Include unnecessary details in subject line
- Use vague descriptions ("update stuff", "fix bug")
- Omit issue references - always link commits to their context
- Use closing keywords (
Fixes) when you only mean to reference (Refs)
Scope Guidelines
Common scopes by area:
feat(auth): login system changes
feat(api): API endpoint changes
feat(ui): user interface changes
feat(db): database schema changes
fix(header): navigation menu bug
fix(footer): copyright date
fix(sidebar): responsive layout
chore(deps): dependency updates
chore(ci): CI/CD configuration
chore(docker): container configuration
Explicit Staging Workflow
Always Stage Files Individually
git status --porcelain
git add src/auth/login.ts
git add src/auth/oauth.ts
git status
git diff --cached --stat
git diff --cached
git commit -m "feat(auth): add OAuth2 support"
Pre-commit Hook Integration
Pre-commit hooks often AUTO-MODIFY files (formatters, linters with autofix). This is expected behavior.
pre-commit run --all-files --show-diff-on-failure
git status --porcelain
git add -u
pre-commit run --all-files
git commit -m "feat(feature): add feature with formatting fixes"
Understanding Pre-commit Exit Codes:
- Exit 0: All hooks passed
- Exit 1: Hook failed OR files were modified (re-stage and re-run)
Pre-commit file modifications are normal - stage them and proceed with the commit.
Explicit Staging Best Practices
git status
git add src/feature/new-file.ts
git add tests/feature.test.ts
git diff --cached --stat
git commit -m "feat(feature): add new feature with tests"
Logical Change Grouping
Group Related Changes
git add src/auth/oauth.ts
git add src/auth/token.ts
git commit -m "feat(auth): implement OAuth2 token handling"
git add tests/auth/oauth.test.ts
git add tests/auth/token.test.ts
git commit -m "test(auth): add OAuth2 integration tests"
git add docs/api/authentication.md
git add README.md
git commit -m "docs(auth): document OAuth2 flow"
Separate Concerns
git add src/**/*.ts
git add .eslintrc
git commit -m "chore(lint): apply ESLint fixes and update config"
git add src/feature/implementation.ts
git add tests/feature.test.ts
git commit -m "feat(feature): add new user management feature"
Change Classification
Linter/Formatting Group:
- Whitespace-only changes
- Lock files (package-lock.json, Cargo.lock)
- Auto-generated linter configs
- Commit type:
chore
Feature/Fix Groups:
- Implementation code
- Related tests
- Relevant documentation
- Commit type:
feat, fix, refactor
Documentation Group:
- README updates
- API documentation
- User guides
- Commit type:
docs
Communication Style
Humble, Fact-Based Messages
git commit -m "fix(auth): handle edge case in token refresh"
git commit -m "feat(api): add pagination support
Implements cursor-based pagination for list endpoints.
Includes tests and documentation."
git commit -m "fix stuff"
git commit -m "AMAZING new feature that revolutionizes everything!!!"
git commit -m "Updated some files to make things work better and faster"
Focus on Facts
- What changed: Describe the change objectively
- Why it changed: Explain the reason if non-obvious
- Impact: Note breaking changes or important effects
git commit -m "perf(db): optimize user query with index
Added composite index on (user_id, created_at) to improve
query performance for user activity feeds.
Reduces query time from 800ms to 45ms for typical workloads."
Workflow Examples
Complete Staging and Commit Flow
git status
pre-commit run --all-files
git add src/feature.ts
git add tests/feature.test.ts
git status
git diff --cached --stat
git commit -m "feat(feature): add new capability
Implements X feature with Y functionality.
Includes unit tests and integration tests.
Closes #123"
git log -1 --stat
Amending Commits
git add forgotten-file.ts
git commit --amend --no-edit
git commit --amend -m "feat(auth): improved OAuth2 implementation"
Interactive Staging
git add -p file.ts
Best Practices
Commit Frequency
- Commit early and often: Small, focused commits
- One logical change per commit: Easier to review and revert
- Keep commits atomic: Each commit should be a complete, working state
Commit Message Length
feat(auth): add OAuth2 support
GitHub Issue References (Autolink Format)
ALWAYS reference related GitHub issues in commit messages. This creates traceability, enables project management, and provides context for future code archaeology.
Autolink Reference Formats
GitHub automatically converts these patterns into clickable links:
| Format | Example | Use Case |
|---|
#N | #123 | Same repository issue/PR |
GH-N | GH-123 | Alternative same-repo format |
owner/repo#N | octo-org/api#456 | Cross-repository reference |
Closing Keywords
GitHub recognizes 9 keywords to automatically close issues when commits merge to the default branch:
| Keyword | Variants | Effect |
|---|
| close | close, closes, closed | Closes the issue |
| fix | fix, fixes, fixed | Closes the issue |
| resolve | resolve, resolves, resolved | Closes the issue |
Reference Syntax Patterns
Fixes
Closes
Resolves
Fixes octo-org/octo-repo#100
Fixes
Refs
Related to
See
Formatting Flexibility
- Case insensitive:
FIXES #123, Fixes #123, fixes #123
- Optional colon:
Fixes: #123, Fixes #123
- Whitespace:
Fixes #123 or Fixes#123 (space optional)
When to Use Each Pattern
| Scenario | Pattern | Example |
|---|
| Bug fix that resolves an issue | Fixes #N | Fixes #123 |
| Feature that completes an issue | Closes #N | Closes #456 |
| Work related to but not completing issue | Refs #N | Refs #789 |
| Partial progress on larger issue | Refs #N | Refs #101 |
| Breaking change with migration guide | See #N | See #202 |
Important: Keywords only auto-close issues when merged to the default branch. PRs targeting other branches link but don't auto-close.
Issue Reference Examples
git commit -m "fix(api): handle timeout
Fixes #123"
git commit -m "feat(ui): redesign dashboard
Implements designs from #456
Closes #457, closes #458"
git commit -m "fix(shared): resolve validation bug
Fixes org/shared-lib#42"
git commit -m "feat(api)!: change authentication
BREAKING CHANGE: API key format changed.
See migration guide: #789"
git commit -m "refactor(auth): extract token validation
Refs #234"
Troubleshooting
Accidentally Staged Wrong Files
git restore --staged wrong-file.ts
git restore --staged .
Wrong Commit Message
git commit --amend -m "corrected message"
git commit --amend -m "corrected message"
git push --force-with-lease origin branch-name
Forgot to Add File to Last Commit
git add forgotten-file.ts
git commit --amend --no-edit
Need to Split Last Commit
git reset --soft HEAD~1
git restore --staged .
git add group1-file.ts
git commit -m "first logical group"
git add group2-file.ts
git commit -m "second logical group"