Transform complex git worktree management into simple, ticket-based development. git wt 101 automatically creates isolated workspaces using dynamic path templates and project codes, replacing lengthy git commands with intelligent defaults.
# Set your worktree location (choose one):
git config --global worktree.defaultPath ".gitWT/{worktree_name}" # Inside repo
git config --global worktree.defaultPath "~/worktrees/{worktree_name}" # Outside repo
git config worktree.defaultPath "~/home/markdown-ticket-{worktree_name}" # Custom location
# NEW: Include project directory name (e.g., super-mario for path /home/projects/super-mario)
git config --global worktree.defaultPath "/worktrees/{project_dir}-{worktree_name}"
git config --global worktree.defaultPath "../{project_dir}_{worktree_name}"
# Or set per-repo:
git config worktree.defaultPath ".gitWT/{worktree_name}"# Just 3 digits (reads project code from .mdt-config.toml)
git wt 101
# Full ticket name
git wt MDT-101
# Custom ticket format
git wt PROJ-123# Remove by ticket number (automatically finds path)
git wt-rm 101
git wt-rm MDT-101
git wt-rm PROJ-123
# Manual removal (require full path)
git worktree remove path/to/worktree# List all worktrees
git worktree list
# Clean up stale worktrees
git worktree prune- Overview
- Installation
- Configuration
- Usage
- Worktree Management
- Advanced Features
- IDE Integration
- Troubleshooting
- Examples
git wt is a custom Git alias that simplifies creating worktrees for ticket-based development. It automatically:
- Extracts ticket numbers from input
- Reads project configuration from
.mdt-config.toml - Creates worktrees in configurable locations
- Generates IntelliJ IDEA scope files for focused development
- Supports both relative and absolute paths
- Isolated Development: Each ticket gets its own worktree
- IDE Scoping: Automatic IDEA scope creation for ticket-specific file filtering
- Flexible Paths: Store worktrees inside or outside the repository
- Smart Naming: Automatically constructs worktree names from project config
- Git 2.15+ (for worktree support)
- Bash/Zsh shell
- Optional: IntelliJ IDEA (for automatic scope support)
Use the command from this gist file: https://gist.github.com/andkirby/e44e984a061a6b61b02249721d11677b#file-git_config_alias_worktree-sh
Set default worktree location for all repositories:
# Inside repository (recommended)
git config --global worktree.defaultPath ".gitWT/{worktree_name}"
# Outside repository
git config --global worktree.defaultPath "~/worktrees/{worktree_name}"
# Custom location with project prefix
git config --global worktree.defaultPath "~/home/markdown-ticket-{worktree_name}"
# Using $HOME directly (no ~ expansion needed)
git config --global worktree.defaultPath "$HOME/worktrees/{worktree_name}"
# NEW: Include project directory name (e.g., super-mario)
git config --global worktree.defaultPath "/worktrees/{project_dir}-{worktree_name}"
git config --global worktree.defaultPath "../{project_dir}_{worktree_name}"Set worktree location for current repository only:
# Relative to repository root
git config worktree.defaultPath ".gitWT/{worktree_name}"
# Absolute path
git config worktree.defaultPath "/Users/username/worktrees/{worktree_name}"
# Without placeholder (will append worktree name)
git config worktree.defaultPath ".gitWT"
# NEW: Include project directory name
git config worktree.defaultPath "../{project_dir}_{worktree_name}"
git config worktree.defaultPath "~/workspaces/{project_dir}-{worktree_name}"Configure project code in .mdt-config.toml:
[project]
name = "Markdown Ticket"
code = "MDT"
cr_path = "docs/CRs"# Create worktree with just ticket number
git wt 101
# Output: Creates MDT-101 if project code is MDT in .mdt-config.toml
# Create worktree with full ticket name
git wt MDT-101
# Create worktree with custom prefix
git wt PROJ-123# Check current configuration
git config worktree.defaultPath # Local config
git config --global worktree.defaultPath # Global config
# Check all git configs
git config --list | grep worktree# List all worktrees
git worktree list
# Switch to a worktree
cd path/to/worktree
# Remove a worktree (deletes branch unless used elsewhere)
git worktree remove path/to/worktree
# Remove worktree but keep branch
git worktree remove --force path/to/worktree
# Clean up stale worktree references
git worktree pruneThe git wt command creates isolated workspaces:
# Basic usage - just ticket number
git wt 101 # Creates worktree for MDT-101 (reads project code)
# Full ticket name
git wt MDT-101 # Creates worktree for MDT-101
# Custom project codes
git wt PROJ-123 # Creates worktree for PROJ-123Features:
- Automatically reads project code from
.mdt-config.toml - Uses configurable path templates with placeholders
- Creates branches automatically
- Supports both relative and absolute paths
The git wt-rm command safely removes worktrees using the same ticket logic:
# Remove by ticket number (automatically finds worktree path)
git wt-rm 101 # Removes MDT-101 worktree and branch
git wt-rm MDT-101 # Removes MDT-101 worktree and branch
git wt-rm PROJ-123 # Removes PROJ-123 worktree and branchSafety Features:
- Path Discovery: Automatically finds worktree using same config logic as
git wt - Interactive Confirmation: Prompts before removing worktree and branch
- Smart Branch Cleanup: Offers to delete branch if no other worktrees use it
- Error Handling: Lists available worktrees if target not found
Removal Process:
- Finds worktree path using
worktree.defaultPathconfiguration - Confirms removal with user
- Removes worktree directory
- Optionally deletes the branch if safe
Example Output:
$ git wt-rm 101
Found worktree: /projects/markdown-ticket/.gitWT/MDT-101
Branch: MDT-101
Remove worktree and branch? [y/N] y
✓ Removed worktree: /projects/markdown-ticket/.gitWT/MDT-101
Delete branch "MDT-101"? [y/N] y
✓ Deleted branch: MDT-101
✓ Worktree removal completedFor advanced usage, you can still use native git commands:
# List all worktrees
git worktree list
# Manual removal (requires full path)
git worktree remove /path/to/worktree
# Remove worktree but keep branch
git worktree remove --force /path/to/worktree
# Clean up stale worktree references
git worktree pruneThe script automatically handles:
-
Relative Paths: Relative to repository root
- Config:
.gitWT/{worktree_name} - Result:
/repo/root/.gitWT/MDT-101
- Config:
-
Absolute Paths: Full paths from filesystem root
- Config:
~/worktrees/{worktree_name} - Result:
/Users/username/worktrees/MDT-101
- Config:
-
Home Directory: Both
~and$HOMEsupported- Config:
~/worktrees/{worktree_name}or$HOME/worktrees/{worktree_name}
- Config:
-
Appending: If no
{worktree_name}placeholder- Config:
.gitWT - Result:
.gitWT/MDT-101
- Config:
-
NEW: Project Folder Placeholder: Uses repository folder name
-
Config:
/worktrees/{project_dir}-{worktree_name} -
From repo
/projects/super-mario, creates:/worktrees/super-mario-MDT-123 -
Config:
../{project_dir}_{worktree_name} -
From repo
/projects/super-mario, creates:/projects/super-mario_MDT-123
-
{worktree_name}: The branch/worktree name (e.g., MDT-123, PROJ-456){project_dir}: Basename of git repository (e.g., super-mario, markdown-ticket)
The script provides clear error messages:
# Missing ticket number
$ git wt abc
error: Must include 3-digit ticket number. E.g. "123" or "MDT-123"
# Worktree already exists
$ git wt 101
error: Worktree already exists at /path/to/worktree
To remove it: git worktree remove /path/to/worktree
# Branch exists without worktree
$ git wt 101
error: Branch "MDT-101" already exists but has no worktree
To create worktree for existing branch: git worktree add /path/to/worktree MDT-101When worktree.defaultPath is not configured, the script:
- Shows warning with explanation
- Provides examples of different configurations
- Offers to set default configuration
- Falls back to
.gitWT/{worktree_name}if declined
# Initial setup
cd ~/projects/markdown-ticket
git config --global worktree.defaultPath ".gitWT/{worktree_name}"
# Create worktrees
git wt 101 # Creates .gitWT/MDT-101
git wt 102 # Creates .gitWT/MDT-102
# Work on ticket 101
cd .gitWT/MDT-101
# (IDEA automatically has ticket 101 scope)# Setup external location
mkdir -p ~/workspaces
git config --global worktree.defaultPath "~/workspaces/{worktree_name}"
# Create worktree
git wt 205 # Creates ~/workspaces/MDT-205
# List worktrees
git worktree list
# /Users/kirby/projects/markdown-ticket abc1234 [main]
# /Users/kirby/workspaces/MDT-205 def5678 [MDT-205]# Project A (MDT prefix)
cd ~/projects/project-a
git config worktree.defaultPath ".gitWT/{worktree_name}"
git wt 001 # Creates .gitWT/MDT-001
# Project B (PROJ prefix)
cd ~/projects/project-b
git config worktree.defaultPath ".gitWT/{worktree_name}"
git wt 001 # Creates .gitWT/PROJ-001# From /projects/super-mario repository
git config --global worktree.defaultPath "/worktrees/{project_dir}-{worktree_name}"
# Creates /worktrees/super-mario-MDT-345
git wt 345
# Relative to parent directory
git config worktree.defaultPath "../{project_dir}_{worktree_name}"
# From /projects/super-mario, creates: /projects/super-mario_MDT-345
git wt 345# Organized by year
git config --global worktree.defaultPath "~/worktrees/2025/{worktree_name}"
# Creates ~/worktrees/2025/MDT-345
git wt 345
# Combine project directory with organization
git config --global worktree.defaultPath "~/worktrees/{project_dir}/{worktree_name}"
# From /projects/super-mario, creates: ~/worktrees/super-mario/MDT-345
git wt 345# Worktree directory deleted but reference remains
git worktree list
# /Users/kirby/.gitWT/MDT-123 abcdef0 [MDT-123]
# Clean up stale reference
git worktree prune
# Recreate worktree
git wt 123
error: Branch "MDT-123" already exists but has no worktree
# Use the suggested command:
git worktree add .gitWT/MDT-123 MDT-123# List worktrees
git worktree list
# /Users/kirby/projects/markdown-ticket abc1234 [main]
# /Users/kirby/projects/markdown-ticket/.gitWT/MDT-101 def5678 [MDT-101]
# Remove by ticket number
git wt-rm 101
Found worktree: /Users/kirby/projects/markdown-ticket/.gitWT/MDT-101
Branch: MDT-101
Remove worktree and branch? [y/N] y
✓ Removed worktree: /Users/kirby/projects/markdown-ticket/.gitWT/MDT-101
Delete branch "MDT-101"? [y/N] y
✓ Deleted branch: MDT-101
✓ Worktree removal completed
# Try to remove non-existent worktree
git wt-rm 999
error: Worktree not found at /Users/kirby/projects/markdown-ticket/.gitWT/MDT-999
Listing existing worktrees:
# /Users/kirby/projects/markdown-ticket abc1234 [main]- Consistent Naming: Always use the same project prefix across repositories
- Regular Cleanup: Run
git worktree pruneperiodically - Backup Strategy: Worktrees share
.gitdirectory, backup the main repo - IDE Integration: Use the automatic IDEA scopes for focused development
- Configuration: Use global config for personal preferences, local for team standards
- Use
git worktree adddirectly for existing branches - Combine with other git aliases:
git config --global alias.sw 'cd $(git worktree list | grep $(git branch --show-current) | cut -f1)' - Create aliases for common operations:
git config --global alias.wtlist 'git worktree list' - Use with git hooks for additional automation
Usage example: