A fast, intuitive command-line tool for managing Git worktrees with smart branch resolution and GitHub integration.
- Smart worktree creation - Automatically handles local, remote, and new branches
- Directory switching - Switch between worktrees with shell integration
- GitHub PR integration - Create worktrees directly from pull requests
- Command execution - Run commands in specific worktree contexts
- Repository initialization - Set up bare repositories optimized for worktrees
- Configurable workflows - Customize behavior with hooks and settings
- Git 2.5+ (for worktree support)
- GitHub CLI (optional, for PR features)
Use the official install script for automatic platform detection and installation:
# Quick install (latest version)
curl -fsSL https://raw.githubusercontent.com/tinmancoding/wt/main/install.sh | bash
# Install specific version
WT_INSTALL_VERSION=v0.2.1 curl -fsSL https://raw.githubusercontent.com/tinmancoding/wt/main/install.sh | bash
# Install to custom path (default: ~/.local/bin)
WT_INSTALL_PATH=/usr/local/bin curl -fsSL https://raw.githubusercontent.com/tinmancoding/wt/main/install.sh | bash
# Verify installation
wt --helpAlternatively, download binaries directly from the releases page:
- Linux:
wt-linux-x64.tar.gzorwt-linux-arm64.tar.gz - macOS:
wt-darwin-x64.ziporwt-darwin-arm64.zip
All binaries include SHA256 checksums for verification.
If you prefer to build from source, see the Development Guide.
# Shell integration setup (one-time)
source <(wt setup --bash) # Add to ~/.bashrc
# source <(wt setup --zsh) # Add to ~/.zshrc
# source <(wt setup --fish) # Add to ~/.config/fish/config.fish
# Create worktree with smart branch resolution
wt create feature-branch
# Switch to worktree (requires shell integration)
wt switch feat # Fuzzy matches feature-branch
wt sw feat # Short alias
wts feat # Ultra-short alias
# Get worktree directory path (for scripts)
wt print-dir feature-branch
# Create worktree from GitHub PR
wt pr 123
# Run command in specific branch context
wt run main "npm test"
# List all worktrees
wt list
# Remove worktree (optionally with branch)
wt remove feature-branch --with-branchWT works best with a bare repository structure:
# Initialize new repository for worktrees
wt init https://github.com/user/repo.git my-project
# Resulting structure:
my-project/
├── .bare/ # Bare git repository
├── .git # Points to .bare directory
├── .wtconfig.json # WT configuration
├── feature-1/ # Worktree directories
├── feature-2/
└── main/WT automatically detects the optimal location for worktrees based on your repository structure. You can customize behavior with a .wtconfig.json file in your repository root:
{
"worktreeDir": "./",
"autoFetch": true,
"confirmDelete": false,
"hooks": {
"postCreate": "./scripts/setup-worktree.sh",
"postRemove": null
},
"defaultBranch": "main"
}The worktreeDir setting uses intelligent auto-detection when not explicitly configured:
Detection Logic:
- Multiple worktrees: Finds the common parent directory of all existing worktrees
- Single worktree: Uses the parent directory of the existing worktree
- No additional worktrees: Defaults to repository root
- Manual override: Set
worktreeDirexplicitly to override auto-detection
Examples:
# Scenario 1: Worktrees as siblings to .bare
/project/
.bare/ # Bare repository
main/ # Main worktree
feature-1/ # Additional worktree
# Auto-detected worktreeDir: "./"
# Scenario 2: Organized worktree directory
/project/
.bare/ # Bare repository
worktrees/
main/ # Main worktree
feature-1/ # Additional worktree
# Auto-detected worktreeDir: "./worktrees/"This ensures new worktrees are created in the same location as existing ones, providing consistent project organization.
wt create <branch>- Create worktree with smart branch resolutionwt print-dir [pattern]- Print directory path of matching worktreewt list- List all worktrees with statuswt remove [pattern] [--with-branch]- Remove worktree
wt switch [pattern]- Switch to worktree (shell function only)wt sw [pattern]- Short alias for switch (shell function only)wts [pattern]- Ultra-short convenience alias
wt pr <pr-number>- Create worktree from GitHub PR
wt init <git-url> [name]- Initialize bare repositorywt setup --bash|--zsh|--fish|--auto- Generate shell wrapper functionswt status- Show repository and worktree statuswt clean- Remove orphaned worktrees
wt run <branch> <command...>- Execute command in worktreewt config- Manage configurationwt config <key>- Show config valuewt config <key> <value>- Set config value
To enable directory switching, WT provides shell wrapper functions that must be sourced into your shell:
Add this line to your shell configuration file:
# Bash: ~/.bashrc
source <(wt setup --bash)
# Zsh: ~/.zshrc
source <(wt setup --zsh)
# Fish: ~/.config/fish/config.fish
source (wt setup --fish | psub)
# Auto-detect shell
source <(wt setup --auto)- Direct Commands: Commands like
wt create,wt list,wt print-dirwork normally - Shell Functions:
wt switch,wt sw, andwtsare shell functions that:- Call
wt print-dirto get the target directory - Use
cdto change to that directory - Fall back to normal error handling if the path resolution fails
- Call
- Seamless switching:
wt switch featureactually changes your current directory - Multiple convenience levels:
wt switch,wt sw, orwtsfor different typing preferences - Script compatibility: Use
wt print-dirdirectly in scripts for path resolution - Clean separation: Core functionality remains shell-independent
For development setup, testing, and contributing guidelines, see the Development Guide.
Git worktrees allow you to have multiple working directories for a single repository, enabling:
- Parallel development - Work on multiple features simultaneously
- Easy context switching - No need to stash/commit when switching branches
- Safe experimentation - Test changes without affecting main workspace
- Efficient reviews - Check out PRs locally without disrupting current work
We welcome contributions! Please see the Development Guide for detailed instructions on setting up your development environment, running tests, and submitting pull requests.
MIT License - see LICENSE file for details.