Git Worktree (wtp)
wtp は git worktree を管理する CLI。stash や branch switch なしで、複数の branch を同時に作業できる。
- 複数の branch を同時に作業する場合
- 2 つの実装を side by side で比較する場合
- 別の directory で PR を review する場合
# worktree 一覧wtp list
# feature branch の worktree を追加wtp add feature/user-auth
# custom path を指定wtp add feature/api-refactor ../project-api-refactor
# merge 後に削除wtp remove feature/user-auth
# worktree に switchwtp switch feature/user-auth
# stale な entry を cleanupwtp pruneDirectory naming convention
Section titled “Directory naming convention”../project-<type>-<description>Types: feature, bugfix, hotfix, experiment, refactor
Config
Section titled “Config”.wtp.local.yml で個人設定 (gitignore 済み):
default_path: "../worktrees"auto_cleanup: trueRecipes
Section titled “Recipes”Feature 作業中の hotfix
Section titled “Feature 作業中の hotfix”# feature で作業中cd ~/project-feature-auth
# 緊急の bug が来たwtp add hotfix/critical-bugcd ../project-hotfix-critical-bug
# 修正、push、feature に戻るcd ~/project-feature-auth
# merge 後に cleanupwtp remove hotfix/critical-bugApproach の比較
Section titled “Approach の比較”# Approach Awtp add experiment/approach-acd ../project-experiment-approach-a
# Approach Bwtp add experiment/approach-bcd ../project-experiment-approach-b
# 比較して良い方を残すLocal PR review
Section titled “Local PR review”wtp add review/pr-123 origin/pull/123cd ../project-review-pr-123
# review 後に cleanupwtp remove review/pr-123Interactive mode (wt + skim)
Section titled “Interactive mode (wt + skim)”| Command | 操作 |
|---|---|
wt | interactive menu (Alt+W でも起動) |
wt list | worktree 一覧 |
wt cd | worktree に switch (interactive) |
wt add | worktree を作成 |
wt rm | worktree を削除 (confirmation 付き) |
短縮形: wtcd, wtadd, wtrm, wtls
Keybinding: Alt+W で menu を開く。
preview に最近の commit と git status が表示される。