Skip to content

bsamek/wt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wt

A lightweight CLI for managing Git worktrees. Work on multiple branches simultaneously without switching contexts.

Installation

Option 1: Go install (recommended)

If you have a working Go installation and $GOPATH/bin (or $GOBIN) in your PATH:

go install .

Option 2: Build from source

go build -o wt .

Move the binary to a directory in your PATH.

Option 3: Download from GitHub releases

Download the executable for your platform from the GitHub releases page and place it in a directory in your PATH.

Shell Integration (Recommended)

To enable automatic directory changing after wt create (cd into the new worktree) and wt remove (cd back to root when removing current worktree), add the shell wrapper to your shell configuration:

Bash (add to ~/.bashrc):

source /path/to/wt.sh

Zsh (add to ~/.zshrc):

source /path/to/wt.sh

Fish (copy to functions directory):

cp /path/to/wt.fish ~/.config/fish/functions/wt.fish

Updating: When upgrading wt, re-run the installation command above to get the latest shell wrapper.

Alternatively, copy the wrapper function directly into your shell config:

Bash/Zsh
wt() {
    local wt_bin
    wt_bin=$(type -P wt 2>/dev/null)
    if [[ -z "$wt_bin" ]]; then
        echo "error: wt binary not found in PATH" >&2
        return 1
    fi
    case "$1" in
        completion|__complete|list|version|"")
            "$wt_bin" "$@"
            return $?
            ;;
    esac
    local dir
    dir=$("$wt_bin" "$@")
    local exit_code=$?
    if [[ $exit_code -eq 0 && -n "$dir" && -d "$dir" ]]; then
        cd "$dir" || return 1
    fi
    return $exit_code
}
Fish
function wt --description "Git worktree manager with auto-cd"
    set -l wt_bin (command -v wt 2>/dev/null)
    if test -z "$wt_bin"
        echo "error: wt binary not found in PATH" >&2
        return 1
    end
    if test (count $argv) -eq 0
        $wt_bin
        return $status
    end
    switch $argv[1]
        case completion __complete list version
            $wt_bin $argv
            return $status
    end
    set -l dir ($wt_bin $argv)
    set -l exit_code $status
    if test $exit_code -eq 0 -a -n "$dir" -a -d "$dir"
        cd $dir
    end
    return $exit_code
end

Usage

wt <command> [options] [args]

Commands

Command Description
jump Jump to a worktree or repository root
create Create a new worktree with branch
remove Remove a worktree and its branch (auto-detects if inside worktree)
list List all worktrees
completion Generate shell completion script (bash, zsh, fish)
version Print version information

Options

Option Description
--hook <path> Custom hook script to run after create (default: .worktree-hook)
-h, --help Show help message

Examples

wt jump                    # Navigate to repository root (from worktree)
wt jump my-feature         # Jump to 'my-feature' worktree
wt create my-feature       # Create worktree for 'my-feature' branch
wt create --hook setup.sh feat    # Create worktree, run setup.sh as hook
wt remove my-feature       # Remove worktree and branch
wt remove                  # Remove current worktree (when inside one)
wt list                    # List all worktrees
wt completion bash         # Generate bash completion script
wt version                 # Print version information

How It Works

Worktrees are created in a .worktrees/ directory at the repository root:

my-repo/
├── .worktrees/
│   ├── my-feature/      # Working directory for my-feature branch
│   └── bugfix/          # Working directory for bugfix branch
└── ...

Each worktree has its own working directory, so you can have different branches checked out simultaneously.

Claude Code Support

If your repository has a .claude/ directory (used by Claude Code for settings and context), wt automatically creates a symlink to it in each new worktree. This keeps your Claude configuration in sync across all worktrees without needing to copy or merge changes.

Shell Completion

wt supports tab completion for bash, zsh, and fish shells. Completions include command names, flags, and dynamic worktree name completion for wt jump and wt remove.

Installation

Bash

# Add to ~/.bashrc
wt completion bash >> ~/.bashrc

# Or load for current session only
source <(wt completion bash)

Zsh

# Add to ~/.zshrc
wt completion zsh >> ~/.zshrc

# Or load for current session only
source <(wt completion zsh)

Fish

wt completion fish > ~/.config/fish/completions/wt.fish

Development

Run tests:

go test ./...

Run tests with coverage:

go test -coverprofile=coverage.out ./...
go tool cover -func=coverage.out

The CI pipeline enforces 100% test coverage.