A smart Git worktree manager specifically designed for Warp Terminal that creates isolated development environments with intelligent tab management.
- 🎯 Smart Branch Detection - Auto-detects your default branch (
main
,master
,develop
) - 📁 Intelligent Worktree Management - Handles existing worktrees and branches gracefully
- 🔄 Smart Tab Reuse - Leverages Warp's tab management to reuse existing tabs when possible
- 🌿 Branch Name Support - Full support for complex branch names (
feature/api/user-management
) - 💬 Clear Feedback - Descriptive status messages and error handling
- ⚡ Lightning Fast - Minimal overhead, maximum productivity
Traditional git workflow often involves:
- Stashing or committing incomplete work to switch branches
- Losing context when switching between features
- Manual terminal navigation between project directories
- Managing multiple terminal windows/tabs manually
nwt solves this by creating isolated worktrees for each branch and intelligently managing your Warp terminal tabs.
curl -fsSL https://raw.githubusercontent.com/zdql/nwt/main/install.sh | bash
-
Clone this repository:
git clone https://github.com/zdql/nwt.git cd nwt
-
Run the installer:
chmod +x install.sh ./install.sh
-
Reload your shell:
source ~/.zshrc # or ~/.bashrc
If you prefer manual setup, add the contents of nwt.zsh
to your shell configuration file (~/.zshrc
or ~/.bashrc
).
# Create a new worktree and branch (auto-detects base branch)
nwt feature/user-authentication
# Create from a specific base branch
nwt feature/payment-integration develop
# Create a hotfix
nwt hotfix/critical-security-fix main
# Complex branch names with slashes
nwt feature/api/v2/user-management
nwt bugfix/ui/modal/close-button
nwt chore/deps/update-react-18
# Different base branches
nwt feature/new-ui main
nwt hotfix/prod-issue production
nwt experiment/new-arch develop
When you run nwt feature/user-auth
from /path/to/myproject
, it creates:
/path/to/
├── myproject/ # Original repository
└── myproject-feature/user-auth/ # New worktree
Scenario | Behavior |
---|---|
New branch | Creates worktree + branch, opens in new Warp tab |
Existing branch, no worktree | Creates worktree, opens in new Warp tab |
Existing worktree | Opens existing worktree (reuses tab if available) |
Already in target worktree | No-op (you're already there!) |
- Remote HEAD: Checks
git symbolic-ref refs/remotes/origin/HEAD
- Common branches: Looks for
main
→master
→develop
- Current branch: Falls back to your current branch (with warning)
# Force current tab behavior (optional)
export NWT_CURRENT_TAB=1 # Navigate in current tab instead of new window
The script detects Warp terminal using the $WARP_IS_LOCAL_SHELL_SESSION
environment variable and optimizes behavior accordingly.
Parameters:
branch-name
: Name of the branch to create/navigate to (required)base-branch
: Base branch for new branches (optional, auto-detected if not provided)
Aliases:
nwt
- Short formnew_worktree
- Full function name
Exit Codes:
0
- Success1
- Error (not in git repo, worktree creation failed, etc.)
"Error: Not in a git repository"
- Make sure you're running the command from within a git repository
- Check that
git rev-parse --show-toplevel
works
"Failed to create worktree"
- Ensure the target directory doesn't already exist
- Check git worktree permissions
- Verify the base branch exists
Warp doesn't open
- Ensure Warp is installed and in your Applications folder
- Check that the
open
command works:open -a "Warp" .
Run with verbose output:
set -x # Enable debug mode
nwt your-branch-name
set +x # Disable debug mode
Contributions are welcome! Please feel free to submit issues, feature requests, or pull requests.
git clone https://github.com/zdql/nwt.git
cd nwt
# Make your changes
# Test thoroughly
Test the function in different scenarios:
- New repository
- Repository with main/master branches
- Existing worktrees
- Complex branch names
MIT License - see LICENSE file for details.
- Warp Terminal for building an amazing terminal
- Git worktree feature for making isolated development environments possible
- The open source community for inspiration and best practices