commit-and-pr

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Commit 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 branches

2. ブランチ戦略

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
    /
    master
    ): use it as is.
  • When on
    main
    /
    master
    : create a new branch. Derive the branch name from the changes (e.g.,
    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 -A
でも可。
Prioritize specifying specific files over
git add -A
. Never include the following:
  • .env files, secrets, authentication information
  • Untracked large binaries
  • Build artifacts listed in
    .gitignore
bash
git add <file1> <file2> ...
If all changed files are safe,
git add -A
can be used.

4. コミット作成

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 が失敗した場合: 問題を修正して再ステージし、新しいコミットを作成(
--amend
禁止)。
Analyze 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 を作成(本文は日本語で記述)。改行が
\n
のままエスケープされないよう、必ず一時ファイル経由で渡す:
bash
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
\n
, always pass it via a temporary file:
bash
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
    /
    master
    へのforce pushは禁止。
  • ユーザーが明示的に求めない限り
    --no-verify
    は使わない。
  • プッシュ済みのコミットを amend しない。
  • 共有・保護ブランチへのプッシュ前はユーザーに確認する。
  • 変更がない場合(
    git status
    がクリーン)はコミットしない。
  • Force pushing to
    main
    /
    master
    is prohibited.
  • Do not use
    --no-verify
    unless explicitly requested by the user.
  • Do not amend pushed commits.
  • Confirm with the user before pushing to shared/protected branches.
  • Do not commit if there are no changes (when
    git status
    is clean).