Commit session changes to git. Use when the user asks to commit, save, checkpoint, or snapshot their work. Also use proactively when working in a git worktree and you've completed a discrete unit of work. Triggers include "commit this", "save my changes", "create a commit", "git commit", "push my changes", "I'm done", "wrap up", or any request to persist the current session's work to version control - even if the user doesn't explicitly say "commit".
Create a single git commit containing only the changes made during this session. Do not create multiple commits. Do not push.
User-initiated (invoked via /commit or an explicit request like "commit this"):
commit on any branch, no questions asked.
Self-initiated (you decide a commit would be appropriate after completing work): you MUST check whether you are in a git worktree:
git worktree list
pwd
Ambiguous (the user says something like "I'm done", "wrap up", "save this", but hasn't explicitly asked for a commit): ask the user whether they want a commit. Do not assume.
Run these commands in parallel to understand the current state:
git log --oneline -15 # Learn the repo's commit style
git status # See what's changed
git diff # Unstaged changes
git diff --staged # Already staged changes
Commit style: Match the existing commits (casing, tense, format, prefixes, length).
The repo's conventions always take priority over generic best practices.
If existing commits use a consistent pattern (e.g. module: description, or imperative lowercase),
follow it exactly. If they are low-quality messages like "fix" or "update", fall back to the
guidelines in Step 3.
Review the conversation history to identify which files were changed as part of this session. Only stage changes directly related to this session's work.
Most common case — all changes in a file are session-related:
git add <file1> <file2> ...
Mixed files — a file has both session and unrelated changes. Since git add -p is interactive
and cannot be used here, use the patch-and-apply approach:
# 1. Generate the full diff for the file
git diff <file> > /tmp/partial.patch
# 2. Edit /tmp/partial.patch to keep ONLY the session-related hunks:
# - Remove entire hunk blocks (from @@ line through to next @@ or end) that aren't session-related
# - Within a hunk: remove `+` lines to exclude additions, change `-` to ` ` to keep deletions
# - Adjust hunk header line counts (@@ -a,b +c,d @@) if you modify hunks
# 3. Apply the filtered patch to the staging area
git apply --cached /tmp/partial.patch
After staging, verify the staged diff matches the session's work:
git diff --staged --stat
git diff --staged
Write a single-line commit message. Keep it short and descriptive.
Fallback guidelines (use only when the repo has no clear style):
git commit -m "<message>"
Do not push. Do not create additional commits. The task is done after the single commit.