Skip to content

Instantly share code, notes, and snippets.

@spilist
Created August 30, 2025 19:03
Show Gist options
  • Select an option

  • Save spilist/cfb116b9e7cae9bea86e4914b68bb840 to your computer and use it in GitHub Desktop.

Select an option

Save spilist/cfb116b9e7cae9bea86e4914b68bb840 to your computer and use it in GitHub Desktop.
Commit guildeline for AGENTS (inspired by https://cbea.ms/git-commit/)

/commit

Create a git commit with a properly formatted message following best practices.

Usage

/commit [message]

Instructions

When the user invokes this command, follow these steps:

1. Check Git Status

First, run git status to see:

  • What files are modified
  • What files are staged
  • What files are untracked

2. Review Changes

Run git diff --cached to review staged changes, and git diff for unstaged changes. Understand the context and purpose of the changes.

3. Stage Files (if needed)

If there are unstaged changes that should be included:

  • Ask the user which files to stage
  • Use git add <files> to stage them
  • Or use git add . if the user wants to stage all changes

4. Create Commit Message

Follow the Seven Rules of Great Commit Messages:

Subject Line (50 chars max)

  • Capitalize the first letter
  • Do not end with a period
  • Use imperative mood - write as if completing: "If applied, this commit will..."
  • Keep it concise and focused

Good examples:

  • Refactor authentication middleware for clarity
  • Add password reset functionality
  • Fix memory leak in data processing pipeline
  • Update API documentation with new endpoints

Bad examples:

  • fixed bug. (lowercase, has period)
  • Adding tests (not imperative)
  • Made changes to login (not imperative, vague)

Body (optional, wrap at 72 chars)

If the change needs more context:

  • Leave a blank line after the subject
  • Explain what and why, not how
  • Provide context about the problem being solved
  • Reference related issues or tickets if applicable

Example of a complete message:

Fix race condition in user session handling

Multiple concurrent requests were causing session data to be 
overwritten. This was particularly noticeable during rapid 
navigation between pages.

The fix implements proper locking mechanisms to ensure session
updates are atomic. This resolves the intermittent logout issues
users were experiencing.

Fixes #234

5. Execute Commit

Create the commit with the properly formatted message:

# For simple commits
git commit -m "Subject line"

# For commits with body (use heredoc or editor)
git commit

6. Confirm Success

Show the commit hash and verify the message formatting.

Examples

User: /commit Assistant:

  1. Check git status and review changes
  2. Understand the context of changes
  3. Stage files if needed
  4. Craft message following the seven rules
  5. Create commit after confirmation

User: /commit Fix memory leak in image processing Assistant:

  1. Verify the message follows best practices
  2. Check git status
  3. Stage necessary files if not already staged
  4. Create commit with provided message

Key Principles

  • Consistency is crucial - follow the same style throughout the project
  • Commit messages should communicate context about why changes were made
  • Good messages help future developers (including yourself) understand the codebase history
  • Think of the commit message as documentation for your code changes

Quick Checklist

Before committing, ensure:

  • Subject line uses imperative mood
  • Subject line is capitalized
  • Subject line has no period at the end
  • Subject line is under 50 characters
  • Body (if present) wraps at 72 characters
  • Body explains why, not how
  • No sensitive information included
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment