A convenient CLI tool for managing Git worktrees with automatic package manager setup.
- Create worktrees with simple commands
- Checkout existing branches as worktrees
- Automatic detection and setup of package managers (npm, yarn, pnpm, cargo, go, pip, bundler, composer)
- Copy untracked environment files (.env, .env.local, etc.) to new worktrees
- Interactive worktree selection for removal
- Interactive branch selection for checkout
- Safety checks before removing worktrees (uncommitted changes, unpushed commits, merge status)
- iTerm2 tab name integration - automatically update tab names when switching worktrees
- Cross-platform support (macOS, Linux)
go install github.com/sotarok/gw@latest
Download the latest binary for your platform from the Releases page.
# AMD64
curl -L https://github.com/sotarok/gw/releases/latest/download/gw_Linux_x86_64.tar.gz | tar xz
sudo mv gw /usr/local/bin/
# ARM64
curl -L https://github.com/sotarok/gw/releases/latest/download/gw_Linux_arm64.tar.gz | tar xz
sudo mv gw /usr/local/bin/
# Intel Mac
curl -L https://github.com/sotarok/gw/releases/latest/download/gw_Darwin_x86_64.tar.gz | tar xz
sudo mv gw /usr/local/bin/
# Apple Silicon
curl -L https://github.com/sotarok/gw/releases/latest/download/gw_Darwin_arm64.tar.gz | tar xz
sudo mv gw /usr/local/bin/
git clone https://github.com/sotarok/gw.git
cd gw
make install
# Run interactive configuration setup
gw init
# View and edit configuration interactively
gw config
# List configuration values (non-interactive)
gw config --list
The gw init
command creates a ~/.gwrc
file with your preferences through an interactive setup.
The gw config
command allows you to view and modify your configuration at any time.
# Create worktree for issue #123 (creates branch "123/impl")
gw start 123
# Create worktree with custom branch name
gw start 476/impl-migration-script
# Create worktree for feature branch
gw start feature/new-feature
# Create worktree based on specific base branch
gw start 456 develop
# Create worktree and copy environment files
gw start 789 --copy-envs
This will:
- Create a new worktree at
../{repository-name}-{identifier}
- Create a new branch (either
{issue-number}/impl
for numbers, or the exact branch name provided) - Change to the new worktree directory
- Optionally copy untracked .env files from the original repository
- Automatically run package manager setup if detected
# Checkout specific branch as worktree
gw checkout feature/auth
# Checkout remote branch
gw checkout origin/feature/api
# Interactive mode - select from list of branches
gw checkout
# Checkout and copy environment files
gw checkout feature/auth --copy-envs
This will:
- Create a new worktree at
../{repository-name}-{branch-name}
- Checkout the specified branch (or create tracking branch for remote)
- Change to the new worktree directory
- Optionally copy untracked .env files from the original repository
- Automatically run package manager setup if detected
# Remove specific worktree
gw end 123
# Interactive mode - select from list
gw end
# Force removal without safety checks
gw end 123 --force
Safety checks include:
- Uncommitted changes
- Unpushed commits
- Merge status with origin/main
The gw
tool can be configured via ~/.gwrc
file. Use gw init
for initial setup or gw config
to modify settings at any time.
# Interactive configuration editor (TUI)
gw config
# List current configuration
gw config --list
The interactive config editor allows you to:
- Navigate settings with arrow keys or j/k
- Toggle boolean values with Enter or Space
- Save changes with 's'
- Quit with 'q'
- View help with '?'
- auto_cd: Automatically change to the new worktree directory after creation (default: true)
- update_iterm2_tab: Update iTerm2 tab name when creating/switching/removing worktrees (default: false)
Example ~/.gwrc
:
# gw configuration file
auto_cd = true
update_iterm2_tab = false
When update_iterm2_tab
is enabled and you're using iTerm2:
- Tab name is updated to "{repository-name} {issue-number/branch-name}" when creating or switching worktrees
- Tab name is reset when removing worktrees
- Only works when running in iTerm2 terminal (automatically detected)
To enable automatic directory changing after creating worktrees, you need to set up shell integration:
Add one of these lines to your shell configuration file:
# For Bash (~/.bashrc)
eval "$(gw shell-integration --show-script --shell=bash)"
# For Zsh (~/.zshrc)
eval "$(gw shell-integration --show-script --shell=zsh)"
# For Fish (~/.config/fish/config.fish)
gw shell-integration --show-script --shell=fish | source
This method ensures you always have the latest shell integration code. See SHELL_INTEGRATION.md for more details.
Future versions will support additional configuration:
- Default base branch
- Custom worktree location
- Package manager preferences
gw/
├── cmd/ # Command implementations
├── internal/
│ ├── git/ # Git operations
│ ├── detect/ # Package manager detection
│ ├── ui/ # Interactive UI components
│ ├── config/ # Configuration management
│ └── iterm2/ # iTerm2 integration
├── main.go
└── go.mod
go build -o gw
# Run tests
go test ./...
# Run tests with coverage
make test
# Generate coverage report
make coverage
# View coverage in terminal
make coverage-report
MIT