A simple git worktree helper that makes managing git worktrees effortless.
- Quickly switch to existing worktrees or create new ones
- Automatically handles branch creation from local, remote, or main branch
- Safely remove worktrees with automatic navigation
- Interactive confirmations to prevent accidents
-
Clone or download this repository:
git clone <repo-url> ~/wt
-
Add the following line to your shell configuration file:
For Bash (
~/.bashrcor~/.bash_profile):source ~/wt/wt.sh
For Zsh (
~/.zshrc):source ~/wt/wt.sh
-
Reload your shell configuration:
source ~/.bashrc # or ~/.zshrc for Zsh
-
Clone this repository into your Zsh custom plugins directory:
git clone <repo-url> ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/wt
-
Add
wtto your plugins array in~/.zshrc:plugins=(... wt)
-
Reload your shell:
source ~/.zshrc
wt lsShows all worktrees in the repository with their paths, branches, and commit info.
Example:
wt lswt <branch-name>This command will:
- Switch to the worktree if it already exists
- Prompt to create a new worktree if it doesn't exist
- Use an existing local branch, or fetch from remote
- Fall back to creating a new branch from
origin/mainorHEAD
Example:
wt feature/new-featurewt remove # Remove current worktree (with confirmation)
wt remove <branch-name> # Remove worktree for specific branch
wt remove --force # Force remove current worktree
wt remove --force <branch-name> # Force removal even with uncommitted changes
wt remove -f <branch-name> # Short formThis command will:
- Remove the current worktree if no branch is specified (prompts for confirmation)
- Find and remove the worktree for the specified branch
- Automatically navigate to another worktree if you're currently in the one being removed
- Prevent removal of the main worktree when using without a branch name
Examples:
wt remove # Remove the current worktree you're in
wt remove feature/old-feature # Remove specific branch's worktree
wt remove --force # Force remove current worktreeBy default, worktrees are created in the parent directory of your repository. You can customize this location by setting the GIT_WT_BASE environment variable:
export GIT_WT_BASE="$HOME/projects/worktrees"Add this to your shell configuration file to make it permanent.
The wt function is a shell wrapper around git worktree commands that:
- Automatically determines the best location for worktrees
- Handles branch existence checks (local and remote)
- Manages safe directory navigation when removing worktrees
- Provides user-friendly prompts and error messages