
commit-and-pr
by rbright
Configuration for Claude Code and other AI agents
SKILL.md
name: commit-and-pr
description: Split staged changes into a sequence of Conventional Commits (reusing repo commit types/scopes), then push and create a GitHub PR via gh using the repo’s PR template.
metadata:
short-description: Auto-commit and open PR
Commit and PR
Goal
Turn a “ready for review” working tree into a clean series of Conventional Commits, then open a GitHub pull request using gh and the repo’s PR template.
When to use
- The plan is implemented, requirements are met, and gates are green.
- All intended changes are staged (index is the source of truth).
Preflight state (before splitting commits)
- Not on a protected branch: don’t run on
main/master(or your repo’s default branch).git branch --show-current
- There are staged changes to commit (the index is your “snapshot” to split).
git diff --cached --name-onlyshould be non-empty
- No extra unstaged changes at the start (so the index is the single source of truth).
git diff --name-onlyshould be empty
ghis authenticated (and the repo has a GitHub remote).gh auth statusgit remote -v
If any guardrail fails, stop and fix the state (don’t “power through”).
Important: During this workflow you will intentionally create unstaged changes as you move files/hunks between commits (e.g. via git reset -- <paths>). That is expected. The preflight requirement is only that the starting point is unambiguous.
1) Learn this repo’s Conventional Commit taxonomy
The goal is to reuse whatever the repo already does (types, scopes, naming), not to invent a new style.
- Collect recent commit subjects (prefer the current branch + recent default-branch history):
git log --format=%s -n 200
- Extract existing Conventional Commit patterns:
type(scope): subjecttype: subject(no scope)
- Build a short “allowed” set from what you see:
- Types used (common:
feat,fix,refactor,docs,test,chore,ci,build,perf) - Scopes used (prefer lowercase kebab-case)
- Types used (common:
Scope normalization rules
- Prefer existing scopes verbatim if they already match repo conventions.
- Normalize new scopes to lowercase kebab-case (e.g.
business-search, notBusinessSearchorbusiness_search). - If history contains an obvious typo variant (e.g.
busines-searchvsbusiness-search), prefer the corrected/most common form and keep future commits consistent.
2) Propose a commit plan (from the staged diff)
Work only from the staged changes:
git diff --cached --name-statusgit diff --cached --statgit diff --cached
Create a short ordered list of commits. Each commit should be:
- Coherent (one “why”)
- Reviewable (small enough to understand)
- Consistent with repo taxonomy (type/scope)
Default ordering (adjust as needed)
build/ci/chore(tooling + scaffolding)refactor(internal-only behavior-preserving reshapes)feat/fix(user-facing behavior changes)test(coverage and regression tests)docs(documentation)
For each planned commit, specify:
- Message:
type(scope): imperative summary - Files: list of staged paths
- Body (optional): why/notes; include
BREAKING CHANGE:footer when applicable
3) Execute the commit plan (default: file-grouped, automatable)
File-grouped mode (recommended)
This mode is deterministic and can be automated end-to-end, but it assumes that a given file belongs to exactly one commit.
Execution pattern:
- Capture the staged file set (the “universe” of changes you’re splitting):
all_paths=$(git diff --cached --name-only)
- For each commit in the plan:
- Remove out-of-scope files from the index (keeps working tree unchanged):
git reset -- <paths-not-in-this-commit>
- Verify staged contents match intent:
git diff --cached --stat
- Commit using Conventional Commits:
git commit -m "type(scope): summary"- Add a body with a second
-mwhen it materially helps review.
- Re-stage remaining files for the next commit:
git add -- $all_paths
- Remove out-of-scope files from the index (keeps working tree unchanged):
Hunk-splitting mode (when a file spans multiple commits)
If a single file must be split across commits, switch to hunk-based staging:
- Use
git reset -pto unstage hunks that belong in later commits. - Use
git add -pto stage hunks for the current commit.
This is more interactive and harder to make fully automatic, but it preserves intent when file boundaries aren’t sufficient.
4) Push the branch
- Ensure you’re on the correct branch:
branch=$(git branch --show-current)
- Push (set upstream if needed):
git push -u origin HEAD
5) Create the PR via gh (using the repo template)
Find the repo’s PR template
Prefer these locations (in order):
.github/PULL_REQUEST_TEMPLATE.md.github/pull_request_template.md.github/PULL_REQUEST_TEMPLATE/*.md
If there are multiple templates, pick the best match for this change (or the “default”).
Choose PR title + body
- Title: Conventional Commits format. Usually mirror the “primary” commit (e.g. first
feat/fix), or summarize the overall change. - Body:
- Start from the PR template content (don’t ignore it).
- Fill in Summary / Test Plan / Notes using facts from the commits and staged diff.
- Keep it concise and reviewer-focused.
Create the PR (non-interactive)
- Determine base branch.
- Default: the repo’s default branch.
- Optional override (per-branch):
git config branch.$(git branch --show-current).gh-merge-base <base>
- Create a body file (in
/tmp) using the repo’s template as the starting point, then fill it in. - Create the PR:
gh pr create --base "$base" --head "$branch" --title "$title" --body-file "$body_file"
Note: gh pr create also supports --template "$template_path", but behavior can vary when combined with explicit --body/--body-file. Keep this workflow deterministic by always inlining template content into "$body_file" yourself and using --body-file.
Example template discovery + body-file creation:
branch="$(git branch --show-current)"
base="$(gh repo view --json defaultBranchRef -q .defaultBranchRef.name 2>/dev/null || echo main)"
template_path="$(
git ls-files |
grep -Ei '^\\.github/(PULL_REQUEST_TEMPLATE\\.md|pull_request_template\\.md|PULL_REQUEST_TEMPLATE/.+\\.md)$' |
head -n 1
)"
body_file="$(mktemp /tmp/pr-body.XXXXXX)"
if [ -n "$template_path" ]; then
cat "$template_path" >"$body_file"
else
: >"$body_file"
fi
cat >>"$body_file" <<'EOF'
## Summary
- …
## Test Plan
- …
EOF
Boundaries
- Do not rewrite history (no
rebase,reset --hard,push --force) unless explicitly requested. - Do not auto-merge. Creating the PR is the end of this workflow.
スコア
総合スコア
リポジトリの品質指標に基づく評価
SKILL.mdファイルが含まれている
ライセンスが設定されている
100文字以上の説明がある
GitHub Stars 100以上
3ヶ月以内に更新がある
10回以上フォークされている
オープンIssueが50未満
プログラミング言語が設定されている
1つ以上のタグが設定されている
レビュー
レビュー機能は近日公開予定です
