commit-and-pr
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCommit and PR
Commit and PR
git commit → push → PR 作成のワークフローを一括で実行する。
Execute the git commit → push → PR creation workflow in one go.
ワークフロー
Workflow
1. 現状確認
1. Check Current Status
以下を並行実行:
bash
git status # 未追跡・変更ファイルを確認
git diff HEAD # 全差分を確認
git log --oneline -5 # 最近のコミットスタイルを把握
git branch -r # リモートブランチの存在確認Execute the following in parallel:
bash
git status # Check untracked and changed files
git diff HEAD # Check all differences
git log --oneline -5 # Understand recent commit styles
git branch -r # Check for existence of remote branches2. ブランチ戦略
2. Branch Strategy
- フィーチャーブランチ上(/
main以外): そのまま使用。master - /
main上: 新しいブランチを作成。変更内容からブランチ名を導出(例:master、feat/add-login)。fix/null-pointer
bash
git checkout -b <branch-name>- When on a feature branch (other than /
main): use it as is.master - When on /
main: create a new branch. Derive the branch name from the changes (e.g.,master,feat/add-login).fix/null-pointer
bash
git checkout -b <branch-name>3. ステージング
3. Staging
git add -A- 、シークレット、認証情報
.env - 未追跡の大きなバイナリ
- に記載済みのビルド成果物
.gitignore
bash
git add <file1> <file2> ...全変更ファイルが安全な場合は でも可。
git add -APrioritize specifying specific files over . Never include the following:
git add -A- .env files, secrets, authentication information
- Untracked large binaries
- Build artifacts listed in
.gitignore
bash
git add <file1> <file2> ...If all changed files are safe, can be used.
git add -A4. コミット作成
4. Create Commit
全変更を分析し、簡潔なコミットメッセージを作成(1〜2文、命令形、what ではなく why に焦点)。heredoc で渡す:
bash
git commit -m "$(cat <<'EOF'
<要約行>
<追加コンテキスト(任意)>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
EOF
)"pre-commit hook が失敗した場合: 問題を修正して再ステージし、新しいコミットを作成( 禁止)。
--amendAnalyze all changes and create a concise commit message (1-2 sentences, imperative mood, focus on why not what). Pass it via heredoc:
bash
git commit -m "$(cat <<'EOF'
<Summary line>
<Additional context (optional)>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
EOF
)"If the pre-commit hook fails: fix the issue, restage, and create a new commit (amending is prohibited).
5. プッシュ → PR 作成
5. Push → Create PR
bash
git push -u origin <branch-name>PR を作成(本文は日本語で記述)。改行が のままエスケープされないよう、必ず一時ファイル経由で渡す:
\nbash
cat > /tmp/pr_body.md << 'EOF'bash
git push -u origin <branch-name>Create a PR (the body is written in Japanese). To ensure line breaks are not escaped as , always pass it via a temporary file:
\nbash
cat > /tmp/pr_body.md << 'EOF'背景・動機
Background/Motivation
<なぜこの変更が必要だったかの文脈>
<Context on why this change was necessary>
概要
Overview
- <変更点1>
- <変更点2>
- <Change 1>
- <Change 2>
レビューのポイント
Review Points
- <特に見てほしい箇所や懸念点>
- <Specific areas to review or concerns>
テスト手順
Test Procedures
- <CIで自動確認できないもの、手動で確認が必要なものだけ記載>
🤖 Generated with Claude Code
EOF
gh pr create --title "<簡潔なタイトル(70字以内)>" --body-file /tmp/pr_body.md
`--body "..."` に直接文字列を渡すと `\n` がエスケープされたまま表示される場合があるため、`--body-file` を使うこと。
PR の URL をユーザーに返す。- <Only items that cannot be automatically checked by CI and require manual verification>
🤖 Generated with Claude Code
EOF
gh pr create --title "<Concise title (within 70 characters)>" --body-file /tmp/pr_body.md
Directly passing a string to `--body "..."` may cause `\n` to remain escaped, so use `--body-file` instead.
Return the PR URL to the user.安全ルール
Safety Rules
- /
mainへのforce pushは禁止。master - ユーザーが明示的に求めない限り は使わない。
--no-verify - プッシュ済みのコミットを amend しない。
- 共有・保護ブランチへのプッシュ前はユーザーに確認する。
- 変更がない場合(がクリーン)はコミットしない。
git status
- Force pushing to /
mainis prohibited.master - Do not use unless explicitly requested by the user.
--no-verify - Do not amend pushed commits.
- Confirm with the user before pushing to shared/protected branches.
- Do not commit if there are no changes (when is clean).
git status