Worktrees

Git Worktrees

Git worktrees allow you to check out multiple branches simultaneously in separate directories.

Why Worktrees?

Development is often interrupted:

  • A critical bug needs immediate attention
  • A colleague needs a code review on their branch
  • Your current task is put on hold
  • You need to compare implementations side-by-side

Without worktrees, you’d stash changes, switch branches, lose context, and later struggle to remember where you were. Worktrees let you keep everything in place.

Native Git vs Workareas

Native git worktree commands are verbose:

# Native git - hard to remember
git worktree add [-f] [--detach] [--checkout] [--lock] [-b <branch>] <path> [<commit-ish>]

# Workareas - simple and tracked
wa add --wt=bugfix --alias=bf --bn=hotfix-123

Worktree Commands

CommandDescription
wa lsList all worktrees on current machine
wa ls --aliasesList only worktrees with aliases
wa add --wt=name --bn=branchCreate new worktree
wa rm --wt=pathRemove a worktree from tracking
wa set --alias=shortnameSet alias for current worktree

Worktree Data Model

When stored in CaseMgr, each worktree tracks:

FieldDescription
nameDisplay name (often from path or alias)
pathFilesystem path on the machine
machine_idHostname identifying which machine
os_typeOperating system (linux, macos, windows)
remote_originGit remote URL (links worktrees across machines)
branchCurrent branch name
headCurrent commit SHA
aliasShort name for quick navigation
workspace_filenameAssociated VS Code workspace file

Multi-Machine Support

With CaseMgr backend, worktrees are tracked per-machine using machine_id. The remote_origin field links the same repository across different machines.

# Export all worktrees (all machines) for backup
wa export wa --all > backup.json

# Import worktrees on a new machine
wa import wa --file=backup.json