Create, remove, and list git worktrees in a standardized location
Manage git worktrees stored in ~/.git-worktrees/<repo>/<branch>, keeping them out of the user's project directories.
Before any operation, determine the repository name:
repo=$(basename "$(git rev-parse --show-toplevel)")
The worktree base directory is always ~/.git-worktrees/$repo/.
If the user provides just a branch name, treat it as a create operation.
repo=$(basename "$(git rev-parse --show-toplevel)")
branch="<branch>"
dir="$HOME/.git-worktrees/$repo/$branch"
mkdir -p "$HOME/.git-worktrees/$repo"
git worktree add "$dir" "$branch"
If the branch doesn't exist yet, use -b to create it from HEAD:
git worktree add -b "$branch" "$dir" HEAD
After creation, always prominently display the worktree path so the user can open a new session pointing to it:
Worktree created at:
~/.git-worktrees/<repo>/<branch>
repo=$(basename "$(git rev-parse --show-toplevel)")
git worktree remove "$HOME/.git-worktrees/$repo/<branch>"
If the worktree has uncommitted changes, warn the user before using --force.
git worktree list
Clean up stale worktree references (e.g., after manually deleting a worktree directory):
git worktree prune
--force without explicit user confirmation