Manage git worktrees for isolated work on parallel branches without switching directories
ChatCLI’s /worktree command integrates with the git worktrees system to allow isolated work on multiple branches simultaneously. Instead of git stash and git checkout, you create separate worktrees and switch between them with a single command.
Git worktrees allow you to have multiple working copies of the same repository, each on a different branch, sharing the same .git. ChatCLI automates the creation, listing, and removal of these worktrees.
Worktree created: Branch: feature/auth Path: /Users/dev/my-project-feature-auth/ CWD changed to: /Users/dev/my-project-feature-auth/Tip: Use /worktree list to see all active worktrees.
1
Automatic branch detection
If the branch already exists in the repository (local or remote), ChatCLI uses it directly. If it doesn’t exist, it creates a new branch from the current HEAD.
2
Directory creation
The worktree directory is created alongside the repository root, with a name based on the branch (slashes replaced with hyphens).
3
CWD change
ChatCLI automatically changes the working directory to the new worktree, allowing subsequent commands to operate in the correct context.
The branch can be an existing branch (local or remote) or a new branch. ChatCLI automatically detects which and acts accordingly.
Worktree removed: Branch: feature/auth Path: /Users/dev/my-project-feature-auth/ (deleted)Note: The branch 'feature/auth' was NOT deleted. Use git branch -d to remove it.
Removing a worktree deletes the directory but does not delete the branch. Uncommitted changes will be lost. Always commit or stash before removing.
Work on a feature without affecting the main branch:
# Create worktree for the feature/worktree create feature/auth# Work normally (CWD already changed)/coder Implement the JWT authentication module# Go back to the main worktree/worktree create main# (detects that main already exists and just changes CWD)
Fix a bug without losing work in progress:
# You're working on feature/auth...# Urgent bug in production!/worktree create hotfix/fix-login# Fix the bug/coder Fix the login bug causing infinite redirect# Go back to the feature/worktree create feature/auth
Review a PR without leaving your branch:
# Create worktree for the PR branch/worktree create feature/new-api# Analyze the code/plan/agent Analyze the changes in this branch and identify potential issues# or, on a single line:# /plan Analyze the changes in this branch and identify potential issues# Remove when done/worktree remove feature/new-api