worktree-tool
v1.2.1
Published
A command-line tool for managing Git worktrees with integrated tmux/shell session management
Downloads
101
Maintainers
Readme
wtt - Git Worktree Tool
A command-line tool for managing Git worktrees with integrated tmux/shell session management.
Features
- 🚀 Quick creation of Git worktrees with automatic branch management
- 🖥️ Automatic tmux session/window creation (when available)
- 🐚 Smart shell integration with custom prompts
- 📁 Organized worktree structure in
.worktrees/directory - 🔧 Simple configuration management
- 🌍 Cross-platform support (Linux, macOS, Windows)
- 🔄 Auto-run commands on worktree creation
- 🔌 Automatic port allocation for development servers
- 📊 Execute commands across multiple worktrees
- 🔤 Automatic tmux window sorting
Installation
From npm
npm install -g worktree-toolFrom source
git clone https://github.com/yourusername/worktree-tool.git
cd worktree-tool
npm install
npm run build
npm linkQuick Start
- Initialize wtt in your Git repository:
wtt init- Create a new worktree:
wtt create feature-awesomeThis will:
- Create a new Git worktree at
.worktrees/feature-awesome - Create a new branch
feature-awesome - Open a new tmux window (if tmux is available) or shell with the worktree name in the prompt
Commands
wtt init
Initialize worktree management in the current repository.
Options:
--project-name <name>- Override automatic project name detection--base-dir <dir>- Set base directory for worktrees (default:.worktrees)--enable-tmux- Force enable tmux integration--disable-tmux- Force disable tmux integration--main-branch <branch>- Override main branch detection
Example:
wtt init --project-name myapp --disable-tmuxwtt create <name>
Create a new worktree with the given name.
Example:
wtt create feature-login
wtt create "fix user authentication" # Spaces are automatically converted to hyphenswtt exec [command]
Execute a command in all (or specified) worktrees.
Options:
-w, --worktrees <worktrees>- Comma-separated list of worktree names--mode <mode>- Execution mode:window,inline,background, orexit--refresh- Ensure autoRun commands are running and re-sort windows-v, --verbose- Show verbose output-q, --quiet- Suppress output
Example:
# Execute predefined command in all worktrees
wtt exec dev
# Execute command in specific worktrees
wtt exec build -w feature-a,feature-b
# Execute inline command
wtt exec -- npm test
# Refresh autoRun commands
wtt exec --refreshwtt help [command]
Display help information.
Example:
wtt help
wtt help initConfiguration
wtt stores its configuration in .worktreerc.json at the repository root:
{
"version": "1.0.0",
"projectName": "my-project",
"mainBranch": "main",
"baseDir": ".worktrees",
"tmux": true,
"autoSort": true,
"availablePorts": "9000-9099",
"commands": {
"dev": {
"command": "npm run dev",
"mode": "window",
"autoRun": true,
"numPorts": 1
},
"test": "npm test"
}
}Configuration Options
autoSort(boolean) - Automatically sort tmux windows alphabetically (default: true)availablePorts(string) - Port range for automatic port allocation (e.g., "9000-9099")commands(object) - Predefined commands for use withwtt exec
Command Configuration
Commands can be defined as either:
- A simple string:
"test": "npm test" - An object with options:
command(string) - The command to executemode(string) - Execution mode:window,inline,background, orexitautoRun(boolean) - Run automatically when creating new worktreesnumPorts(number) - Number of ports to allocate (setsWTT_PORT1,WTT_PORT2, etc.)
Port Allocation
When availablePorts is configured and a command has numPorts set, wtt will:
- Find available ports in the specified range
- Set environment variables
WTT_PORT1,WTT_PORT2, etc. - Pass these to the executed command
This is useful for running development servers on different ports in each worktree.
Auto-Run Commands
Commands with autoRun: true will automatically execute when:
- A new worktree is created with
wtt create - You run
wtt exec --refreshto restart any stopped commands
This is perfect for starting development servers, watchers, or other long-running processes.
Requirements
- Node.js >= 18.0.0
- Git
- tmux (optional, for session management)
Development
This project uses wtt for its own development:
# Clone the repository
git clone https://github.com/yourusername/worktree-tool.git
cd worktree-tool
# Install dependencies
npm install
# Build the project
npm run build
# Initialize wtt for self-hosting
wtt init --project-name=wtt
# Create a worktree for development
wtt create feature-new-command
# Run tests
npm test
npm run test:integration
npm run test:e2e
# Run in development mode
npm run dev -- helpScripts
npm run build- Build the TypeScript projectnpm test- Run unit testsnpm run test:coverage- Run tests with coveragenpm run lint- Run ESLintnpm run typecheck- Run TypeScript type checking
Commit Convention
This project uses Conventional Commits. Use npx cz to commit changes with the interactive commit helper.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT
