An Oh-My-Zsh plugin for managing git worktrees with ease. Streamline your workflow when working with multiple branches simultaneously.
- worktree dir - Initialize a new bare repository with worktree structure from any git URL
- worktree setup - Create a new worktree with automatic branch creation, config file copying, and dependency installation
- worktree list - List all worktrees with pretty formatting
- worktree remove - Remove a worktree with confirmation and optional branch deletion
- β¨ Interactive menu when called without arguments
- β¨οΈ Tab completion for worktree names
- worktree pull - Pull latest changes with automatic stash/unstash
- wt - Quick navigation between worktrees
- β¨οΈ Tab completion for worktree names
- worktree review - Create a worktree from a GitHub PR for easy code review
- wtp - Alias for
worktree pull
- Oh-My-Zsh installed
- Git 2.15+ (for worktree support)
- GitHub CLI (gh) (required for
worktree reviewcommand) - Yarn (for dependency installation)
# Clone the repository
cd ~/GitHub
git clone https://github.com/tmbtech/zsh-git-worktree-manager.git
# Create symlink to Oh-My-Zsh custom plugins directory
ln -s ~/GitHub/zsh-git-worktree-manager ~/.oh-my-zsh/custom/plugins/git-worktree-manager
# Add to your ~/.zshrc plugins array
# Open ~/.zshrc and find the plugins array, then add:
plugins=(git zsh-autosuggestions brew git-worktree-manager)
# Reload your shell
source ~/.zshrccd ~/GitHub/zsh-git-worktree-manager
./install.shThen follow the instructions to add git-worktree-manager to your plugins array in ~/.zshrc.
Initialize a new repository with bare repository worktree structure:
# Auto-generate directory name (creates {repo-name}-worktrees)
worktree dir https://github.com/user/my-repo.git
# Creates: ./my-repo-worktrees/
# Use custom directory name
worktree dir https://github.com/user/my-repo.git custom-project
# Creates: ./custom-project/
# Works with HTTPS URLs too
worktree dir https://github.com/user/another-repo.git
# Show help
worktree dir --helpWhat it does:
- Creates parent directory in your current location
- Clones repository as a bare repo into
.bare/ - Configures
.gitpointer file - Sets up fetch/pull configuration
- Creates initial
mainworktree
After creation:
- Navigate to the main worktree:
cd {dir-name}/main - Copy your config files (*.env, certs) into the main directory
- Run
yarn installornpm install - Create additional worktrees with
worktree setup
Create a new worktree with automatic configuration:
# Basic usage - creates a new worktree from main branch
worktree setup feature/my-feature
# Skip yarn install
worktree setup --skip-yarn bugfix/critical-fix
# Create from a different base branch
worktree setup --base=develop feature/new-thing
# Show help
worktree setup --helpWhat it does:
- Updates the base branch (default: auto-detected from remote)
- Creates a new worktree and branch
- Copies environment files (*.env, key.pem, cert.pem)
- Installs dependencies with yarn
- Navigates you to the new worktree
Display all worktrees in a formatted list:
worktree listRemove a worktree with confirmation:
# Remove a specific worktree
worktree remove feature/my-feature
# Interactive mode - select from a menu (no arguments)
worktree remove
# Tab completion - press TAB to see available worktrees
worktree remove <TAB>What it does:
- Shows interactive selection menu if no worktree name provided
- Confirms worktree removal
- Removes the worktree
- Optionally deletes the associated branch
- Handles force deletion if branch has unmerged changes
Interactive Mode: When called without arguments, displays a numbered menu of all removable worktrees (excluding the protected "main" worktree). Type the number of your selection and press Enter. Press Ctrl+C to cancel.
Pull latest changes in the current worktree:
worktree pull
# Or use the alias
wtpWhat it does:
- Checks for uncommitted changes and stashes them
- Fetches from remote
- Pulls changes
- Restores stashed changes
Quick navigation to worktree root or specific worktree:
# Navigate to worktree root
wt
# Navigate to specific worktree
wt feature/my-feature
# Tab completion - press TAB to see all available worktrees
wt <TAB>Remove stale worktrees whose remote branch has been deleted:
# Preview what would be removed
worktree clean --dry-run
# Remove stale worktrees (with confirmation)
worktree clean
# Skip confirmation prompt
worktree clean -y
# Also remove worktrees with unpushed commits (e.g. squash-merged PRs)
worktree clean --include-unpushed
# Show help
worktree clean --helpWhat it does:
- Fetches from remote and prunes deleted branch refs
- Scans all worktrees (excluding protected "main")
- Identifies worktrees whose remote branch no longer exists
- Skips worktrees with uncommitted changes or unpushed commits
- Confirms removal, then deletes worktrees and their local branches
Create a worktree from a GitHub PR for code review:
worktree review https://github.com/owner/repo/pull/123What it does:
- Fetches PR information using gh CLI
- Creates a worktree with name
pr-<branch-name> - Sets up upstream tracking
- Copies environment files
- Installs dependencies
- Navigates you to the PR worktree
This plugin automatically:
- Detects worktree root directory
- Uses
yarnfor dependency installation (configurable) - Skips Husky hooks during worktree creation
- Copies
.envfiles,key.pem, andcert.pemto new worktrees
This warning appears when the plugin cannot find your worktree structure. Make sure:
- You're running commands from within a worktree
- You have a
mainworktree directory
For the worktree review command, you need the GitHub CLI:
brew install gh
gh auth loginMake sure you:
- Added
git-worktree-managerto the plugins array in~/.zshrc - Reloaded your shell with
source ~/.zshrc
You can skip yarn installation with:
worktree setup --skip-yarn my-branchThen manually run yarn install when ready.
Contributions are welcome! Here's how you can help:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes using Commitizen format
- Push to your branch (
git push origin feature/amazing-feature) - Open a Pull Request
We use Conventional Commits format:
<type>(<scope>): <description>
Example:
feat(worktree): add support for custom config files
fix(pr-review): handle edge case with branch names
docs: update installation instructions
MIT License - see LICENSE file for details
Created to streamline worktree workflows for development teams working with monorepos and feature branches.
If you encounter issues or have questions:
- Check the Troubleshooting section
- Review existing GitHub Issues
- Open a new issue with detailed information about your environment and the problem
Made with β€οΈ for efficient git workflows