GH Commit
Goal
Turn the current working tree into a small set of clean commits without mixing unrelated changes.
Workflow
- Verify git context.
- Run
git rev-parse --show-toplevelandgit status -sb. - Read the branch with
git branch --show-current. - If the branch is
mainormaster, stop and ask the user to switch/create a branch (recommendcodex/...) unless they explicitly asked to commit on that branch.
- Inspect all changes before staging anything.
- Run
git diff --statandgit diff --cached --stat. - List untracked files with
git ls-files --others --exclude-standard. - Read actual hunks with
git diffandgit diff --cached. - Include untracked files in the review (read them if needed) so commit grouping decisions cover the full diff.
- Propose semantic commit groups.
- Group by intent, not just file type (for example: bug fix, refactor, tests, docs).
- Keep user-authored unrelated work separate.
- Call out any files that need partial staging because they contain mixed concerns.
- Create each commit group.
- Stage only the files or hunks for that group (
git add <paths>orgit add -p). - Verify exactly what is staged with
git diff --cached --statandgit diff --cached. - Commit with a concise imperative message.
- Prefer
type(scope): summarywhen the change has an obvious type/scope; otherwise use a clear plain-English summary.
- Repeat until done.
- After each commit, re-check
git status -sb. - Continue until all intended changes are committed or intentionally left uncommitted.
- Report the result.
- List the commit SHAs and messages in order.
- Note any remaining staged/unstaged/untracked files.
Safety Rules
- Avoid
git add -Aunless the entire remaining diff belongs in one commit. - Use partial staging when a file mixes multiple concerns.
- Do not rewrite or discard user changes unless explicitly asked.
- If grouping is ambiguous, ask before committing.