jpskill.com
🛠️ 開発・MCP コミュニティ 🔴 エンジニア向け 👤 エンジニア・AI開発者

🛠️ Git Advanced Workflows

git-advanced-workflows

複雑な開発プロジェクトでも、Git(バージョン

⏱ コードレビュー 1時間 → 10分

📺 まず動画で見る(YouTube)

▶ 【衝撃】最強のAIエージェント「Claude Code」の最新機能・使い方・プログラミングをAIで効率化する超実践術を解説! ↗

※ jpskill.com 編集部が参考用に選んだ動画です。動画の内容と Skill の挙動は厳密には一致しないことがあります。

📜 元の英語説明(参考)

Master advanced Git techniques to maintain clean history, collaborate effectively, and recover from any situation with confidence.

🇯🇵 日本人クリエイター向け解説

一言でいうと

複雑な開発プロジェクトでも、Git(バージョン

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o git-advanced-workflows.zip https://jpskill.com/download/2920.zip && unzip -o git-advanced-workflows.zip && rm git-advanced-workflows.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/2920.zip -OutFile "$d\git-advanced-workflows.zip"; Expand-Archive "$d\git-advanced-workflows.zip" -DestinationPath $d -Force; ri "$d\git-advanced-workflows.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して git-advanced-workflows.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → git-advanced-workflows フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-17
取得日時
2026-05-17
同梱ファイル
1

💬 こう話しかけるだけ — サンプルプロンプト

  • Git Advanced Workflows を使って、最小構成のサンプルコードを示して
  • Git Advanced Workflows の主な使い方と注意点を教えて
  • Git Advanced Workflows を既存プロジェクトに組み込む方法を教えて

これをClaude Code に貼るだけで、このSkillが自動発動します。

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

[Skill 名] git-advanced-workflows

Git の高度なワークフロー

高度な Git テクニックを習得し、クリーンな履歴を維持し、効果的に共同作業を行い、あらゆる状況から自信を持って回復できるようになりましょう。

このスキルを使用しない場合

  • タスクが Git の高度なワークフローと無関係な場合
  • この範囲外の異なるドメインやツールが必要な場合

指示

  • 目標、制約、必要な入力を明確にしてください。
  • 関連するベストプラクティスを適用し、結果を検証してください。
  • 実用的な手順と検証を提供してください。
  • 詳細な例が必要な場合は、resources/implementation-playbook.md を開いてください。

このスキルを使用する場合

  • マージ前のコミット履歴のクリーンアップ
  • 特定のコミットをブランチ間で適用する
  • バグを導入したコミットを見つける
  • 複数の機能を同時に開発する
  • Git の間違いや失われたコミットからの回復
  • 複雑なブランチワークフローの管理
  • レビュー用のクリーンな PR の準備
  • 分岐したブランチの同期

コアコンセプト

1. インタラクティブなリベース

インタラクティブなリベースは、Git 履歴編集のスイスアーミーナイフです。

一般的な操作:

  • pick: コミットをそのまま保持
  • reword: コミットメッセージを変更
  • edit: コミット内容を修正
  • squash: 前のコミットと結合
  • fixup: squash と同様だがメッセージを破棄
  • drop: コミットを完全に削除

基本的な使用法:

# 直近の5つのコミットをリベース
git rebase -i HEAD~5

# 現在のブランチのすべてのコミットをリベース
git rebase -i $(git merge-base HEAD main)

# 特定のコミットにリベース
git rebase -i abc123

2. チェリーピック

ブランチ全体をマージすることなく、特定のコミットをあるブランチから別のブランチに適用します。

# 単一のコミットをチェリーピック
git cherry-pick abc123

# コミットの範囲をチェリーピック(開始は排他的)
git cherry-pick abc123..def456

# コミットせずにチェリーピック(変更をステージングのみ)
git cherry-pick -n abc123

# チェリーピックしてコミットメッセージを編集
git cherry-pick -e abc123

3. Git Bisect

コミット履歴を二分探索して、バグを導入したコミットを見つけます。

# Bisectを開始
git bisect start

# 現在のコミットを不良としてマーク
git bisect bad

# 既知の良好なコミットをマーク
git bisect good v1.0.0

# Git は中間のコミットをチェックアウトします - テストしてください
# その後、良好または不良としてマークします
git bisect good  # または: git bisect bad

# バグが見つかるまで続行
# 完了したら
git bisect reset

自動化された Bisect:

# スクリプトを使用して自動的にテスト
git bisect start HEAD v1.0.0
git bisect run ./test.sh

# test.sh は良好な場合は 0、不良な場合は 1-127 (125を除く) で終了する必要があります

4. Worktrees

スタッシュや切り替えなしに、複数のブランチで同時に作業します。

# 既存のワークツリーを一覧表示
git worktree list

# フィーチャーブランチ用の新しいワークツリーを追加
git worktree add ../project-feature feature/new-feature

# ワークツリーを追加して新しいブランチを作成
git worktree add -b bugfix/urgent ../project-hotfix main

# ワークツリーを削除
git worktree remove ../project-feature

# 古いワークツリーを削除
git worktree prune

5. Reflog

あなたのセーフティネット - 削除されたコミットを含むすべての参照の動きを追跡します。

# Reflogを表示
git reflog

# 特定のブランチの Reflogを表示
git reflog show feature/branch

# 削除されたコミットを復元
git reflog
# コミットハッシュを見つける
git checkout abc123
git branch recovered-branch

# 削除されたブランチを復元
git reflog
git branch deleted-branch abc123

実践的なワークフロー

ワークフロー 1: PR 前のフィーチャーブランチのクリーンアップ

# フィーチャーブランチから開始
git checkout feature/user-auth

# 履歴をクリーンアップするためのインタラクティブなリベース
git rebase -i main

# リベース操作の例:
# - 「typo を修正」コミットを squash する
# - 明確にするためにコミットメッセージを reword する
# - コミットを論理的に並べ替える
# - 不要なコミットを drop する

# クリーンアップされたブランチを強制プッシュ(他の誰も使用していない場合は安全)
git push --force-with-lease origin feature/user-auth

ワークフロー 2: 複数のリリースにホットフィックスを適用

# main で修正を作成
git checkout main
git commit -m "fix: critical security patch"

# リリースブランチに適用
git checkout release/2.0
git cherry-pick abc123

git checkout release/1.9
git cherry-pick abc123

# 競合が発生した場合は処理
git cherry-pick --continue
# または
git cherry-pick --abort

ワークフロー 3: バグの導入箇所を見つける

# Bisectを開始
git bisect start
git bisect bad HEAD
git bisect good v2.1.0

# Git は中間のコミットをチェックアウトします - テストを実行
npm test

# テストが失敗した場合
git bisect bad

# テストが成功した場合
git bisect good

# Git はテストする次のコミットを自動的にチェックアウトします
# バグが見つかるまで繰り返す

# 自動化されたバージョン
git bisect start HEAD v2.1.0
git bisect run npm test

ワークフロー 4: マルチブランチ開発

# メインプロジェクトディレクトリ
cd ~/projects/myapp

# 緊急バグ修正用のワークツリーを作成
git worktree add ../myapp-hotfix hotfix/critical-bug

# 別ディレクトリでホットフィックス作業
cd ../myapp-hotfix
# 変更を加え、コミット
git commit -m "fix: resolve critical bug"
git push origin hotfix/critical-bug

# 中断することなくメイン作業に戻る
cd ~/projects/myapp
git fetch origin
git cherry-pick hotfix/critical-bug

# 完了したらクリーンアップ
git worktree remove ../myapp-hotfix

ワークフロー 5: 間違いからの回復

# 誤って間違ったコミットにリセットしてしまった
git reset --hard HEAD~5  # ああ、しまった!

# reflog を使用して失われたコミットを見つける
git reflog
# 出力例:
# abc123 HEAD@{0}: reset: moving to HEAD~5
# def456 HEAD@{1}: commit: my important changes

# 失われたコミットを復元
git reset --hard def456

# または失われたコミットからブランチを作成
git branch recovery def456

高度なテクニック

リベース vs マージ戦略

リベースを使用する場合:

  • プッシュする前にローカルコミットをクリーンアップする
  • フィーチャーブランチを main と同期させる
  • レビューを容易にするために線形履歴を作成する

マージを使用する場合:

  • 完了した機能を main に統合する
  • コラボレーションの正確な履歴を保持する
  • 他の人が使用する公開ブランチ
# main の変更でフィーチャーブランチを更新(リベース)
git checkout feature/my-feature
git fetch origin
git rebase origin/main

# 競合を処理
git status
# ファイルの競合を修正
git add .
git rebase --continue

# または代わりにマージ
git merge origin/
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

Git Advanced Workflows

Master advanced Git techniques to maintain clean history, collaborate effectively, and recover from any situation with confidence.

Do not use this skill when

  • The task is unrelated to git advanced workflows
  • You need a different domain or tool outside this scope

Instructions

  • Clarify goals, constraints, and required inputs.
  • Apply relevant best practices and validate outcomes.
  • Provide actionable steps and verification.
  • If detailed examples are required, open resources/implementation-playbook.md.

Use this skill when

  • Cleaning up commit history before merging
  • Applying specific commits across branches
  • Finding commits that introduced bugs
  • Working on multiple features simultaneously
  • Recovering from Git mistakes or lost commits
  • Managing complex branch workflows
  • Preparing clean PRs for review
  • Synchronizing diverged branches

Core Concepts

1. Interactive Rebase

Interactive rebase is the Swiss Army knife of Git history editing.

Common Operations:

  • pick: Keep commit as-is
  • reword: Change commit message
  • edit: Amend commit content
  • squash: Combine with previous commit
  • fixup: Like squash but discard message
  • drop: Remove commit entirely

Basic Usage:

# Rebase last 5 commits
git rebase -i HEAD~5

# Rebase all commits on current branch
git rebase -i $(git merge-base HEAD main)

# Rebase onto specific commit
git rebase -i abc123

2. Cherry-Picking

Apply specific commits from one branch to another without merging entire branches.

# Cherry-pick single commit
git cherry-pick abc123

# Cherry-pick range of commits (exclusive start)
git cherry-pick abc123..def456

# Cherry-pick without committing (stage changes only)
git cherry-pick -n abc123

# Cherry-pick and edit commit message
git cherry-pick -e abc123

3. Git Bisect

Binary search through commit history to find the commit that introduced a bug.

# Start bisect
git bisect start

# Mark current commit as bad
git bisect bad

# Mark known good commit
git bisect good v1.0.0

# Git will checkout middle commit - test it
# Then mark as good or bad
git bisect good  # or: git bisect bad

# Continue until bug found
# When done
git bisect reset

Automated Bisect:

# Use script to test automatically
git bisect start HEAD v1.0.0
git bisect run ./test.sh

# test.sh should exit 0 for good, 1-127 (except 125) for bad

4. Worktrees

Work on multiple branches simultaneously without stashing or switching.

# List existing worktrees
git worktree list

# Add new worktree for feature branch
git worktree add ../project-feature feature/new-feature

# Add worktree and create new branch
git worktree add -b bugfix/urgent ../project-hotfix main

# Remove worktree
git worktree remove ../project-feature

# Prune stale worktrees
git worktree prune

5. Reflog

Your safety net - tracks all ref movements, even deleted commits.

# View reflog
git reflog

# View reflog for specific branch
git reflog show feature/branch

# Restore deleted commit
git reflog
# Find commit hash
git checkout abc123
git branch recovered-branch

# Restore deleted branch
git reflog
git branch deleted-branch abc123

Practical Workflows

Workflow 1: Clean Up Feature Branch Before PR

# Start with feature branch
git checkout feature/user-auth

# Interactive rebase to clean history
git rebase -i main

# Example rebase operations:
# - Squash "fix typo" commits
# - Reword commit messages for clarity
# - Reorder commits logically
# - Drop unnecessary commits

# Force push cleaned branch (safe if no one else is using it)
git push --force-with-lease origin feature/user-auth

Workflow 2: Apply Hotfix to Multiple Releases

# Create fix on main
git checkout main
git commit -m "fix: critical security patch"

# Apply to release branches
git checkout release/2.0
git cherry-pick abc123

git checkout release/1.9
git cherry-pick abc123

# Handle conflicts if they arise
git cherry-pick --continue
# or
git cherry-pick --abort

Workflow 3: Find Bug Introduction

# Start bisect
git bisect start
git bisect bad HEAD
git bisect good v2.1.0

# Git checks out middle commit - run tests
npm test

# If tests fail
git bisect bad

# If tests pass
git bisect good

# Git will automatically checkout next commit to test
# Repeat until bug found

# Automated version
git bisect start HEAD v2.1.0
git bisect run npm test

Workflow 4: Multi-Branch Development

# Main project directory
cd ~/projects/myapp

# Create worktree for urgent bugfix
git worktree add ../myapp-hotfix hotfix/critical-bug

# Work on hotfix in separate directory
cd ../myapp-hotfix
# Make changes, commit
git commit -m "fix: resolve critical bug"
git push origin hotfix/critical-bug

# Return to main work without interruption
cd ~/projects/myapp
git fetch origin
git cherry-pick hotfix/critical-bug

# Clean up when done
git worktree remove ../myapp-hotfix

Workflow 5: Recover from Mistakes

# Accidentally reset to wrong commit
git reset --hard HEAD~5  # Oh no!

# Use reflog to find lost commits
git reflog
# Output shows:
# abc123 HEAD@{0}: reset: moving to HEAD~5
# def456 HEAD@{1}: commit: my important changes

# Recover lost commits
git reset --hard def456

# Or create branch from lost commit
git branch recovery def456

Advanced Techniques

Rebase vs Merge Strategy

When to Rebase:

  • Cleaning up local commits before pushing
  • Keeping feature branch up-to-date with main
  • Creating linear history for easier review

When to Merge:

  • Integrating completed features into main
  • Preserving exact history of collaboration
  • Public branches used by others
# Update feature branch with main changes (rebase)
git checkout feature/my-feature
git fetch origin
git rebase origin/main

# Handle conflicts
git status
# Fix conflicts in files
git add .
git rebase --continue

# Or merge instead
git merge origin/main

Autosquash Workflow

Automatically squash fixup commits during rebase.

# Make initial commit
git commit -m "feat: add user authentication"

# Later, fix something in that commit
# Stage changes
git commit --fixup HEAD  # or specify commit hash

# Make more changes
git commit --fixup abc123

# Rebase with autosquash
git rebase -i --autosquash main

# Git automatically marks fixup commits

Split Commit

Break one commit into multiple logical commits.

# Start interactive rebase
git rebase -i HEAD~3

# Mark commit to split with 'edit'
# Git will stop at that commit

# Reset commit but keep changes
git reset HEAD^

# Stage and commit in logical chunks
git add file1.py
git commit -m "feat: add validation"

git add file2.py
git commit -m "feat: add error handling"

# Continue rebase
git rebase --continue

Partial Cherry-Pick

Cherry-pick only specific files from a commit.

# Show files in commit
git show --name-only abc123

# Checkout specific files from commit
git checkout abc123 -- path/to/file1.py path/to/file2.py

# Stage and commit
git commit -m "cherry-pick: apply specific changes from abc123"

Best Practices

  1. Always Use --force-with-lease: Safer than --force, prevents overwriting others' work
  2. Rebase Only Local Commits: Don't rebase commits that have been pushed and shared
  3. Descriptive Commit Messages: Future you will thank present you
  4. Atomic Commits: Each commit should be a single logical change
  5. Test Before Force Push: Ensure history rewrite didn't break anything
  6. Keep Reflog Aware: Remember reflog is your safety net for 90 days
  7. Branch Before Risky Operations: Create backup branch before complex rebases
# Safe force push
git push --force-with-lease origin feature/branch

# Create backup before risky operation
git branch backup-branch
git rebase -i main
# If something goes wrong
git reset --hard backup-branch

Common Pitfalls

  • Rebasing Public Branches: Causes history conflicts for collaborators
  • Force Pushing Without Lease: Can overwrite teammate's work
  • Losing Work in Rebase: Resolve conflicts carefully, test after rebase
  • Forgetting Worktree Cleanup: Orphaned worktrees consume disk space
  • Not Backing Up Before Experiment: Always create safety branch
  • Bisect on Dirty Working Directory: Commit or stash before bisecting

Recovery Commands

# Abort operations in progress
git rebase --abort
git merge --abort
git cherry-pick --abort
git bisect reset

# Restore file to version from specific commit
git restore --source=abc123 path/to/file

# Undo last commit but keep changes
git reset --soft HEAD^

# Undo last commit and discard changes
git reset --hard HEAD^

# Recover deleted branch (within 90 days)
git reflog
git branch recovered-branch abc123

Resources

  • references/git-rebase-guide.md: Deep dive into interactive rebase
  • references/git-conflict-resolution.md: Advanced conflict resolution strategies
  • references/git-history-rewriting.md: Safely rewriting Git history
  • assets/git-workflow-checklist.md: Pre-PR cleanup checklist
  • assets/git-aliases.md: Useful Git aliases for advanced workflows
  • scripts/git-clean-branches.sh: Clean up merged and stale branches

Limitations

  • Use this skill only when the task clearly matches the scope described above.
  • Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
  • Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.