---
name: Branch Merge Cleanup
slug: branch-merge-cleanup
category: DevOps
description: Branch Merge Cleanup merges a finished branch into main, deletes the branch, and removes any related worktree. Use it after all changes are committed and you want to tidy up the local Git state.
github: "https://github.com/K9i-0/ccpocket/tree/main/.claude/skills/merge"
language: Dart
stars: 1039
forks: 97
install: "npx degit https://github.com/K9i-0/ccpocket/tree/main/.claude/skills/merge ~/.claude/skills/merge"
installs_to: ~/.claude/skills/merge
source_path: .claude/skills/merge/SKILL.md
collection_size: 18
category_size: 798
collection_url: "https://dirskills.com/collections/K9i-0/ccpocket"
added: 2026-08-21T05:14:05.071Z
last_synced: 2026-08-21T05:14:05.071Z
canonical_url: "https://dirskills.com/skills/branch-merge-cleanup"
---

# Branch Merge Cleanup

Branch Merge Cleanup merges a finished branch into main, deletes the branch, and removes any related worktree. Use it after all changes are committed and you want to tidy up the local Git state.

**Install:**

```bash
npx degit https://github.com/K9i-0/ccpocket/tree/main/.claude/skills/merge ~/.claude/skills/merge
```

## README

# ブランチマージ & クリーンアップ

作業ブランチを main にマージし、不要になったブランチと worktree を削除する。

## 前提条件

- 作業ブランチで全ての変更がコミット済みであること
- 現在のブランチが main **でない**こと

## 手順

### 1. 事前確認

```bash
git branch --show-current
```

- 現在のブランチ名を記録する（= `<branch>` とする）
- `main` の場合はマージ対象がないため中断する

```bash
git status --short
```

- 未コミットの変更がある場合は中断し、先にコミットするよう促す

### 2. main に切り替え

```bash
git checkout main
```

### 3. マージ (--no-ff)

```bash
git merge --no-ff <branch>
```

- マージコンフリクトが発生した場合は中断してユーザーに報告する

### 4. 作業ブランチの削除

```bash
git branch -d <branch>
```

### 5. worktree のクリーンアップ

```bash
git worktree list
```

- `<branch>` に紐づく worktree がある場合のみ以下を実行:

```bash
git worktree remove <worktree-path>
```

- worktree ディレクトリが残っている場合は手動削除が必要な旨を通知する

### 6. 完了報告

最終状態を表示する:

```bash
git log --oneline -5
git branch
git worktree list
```
