Skip to content

elithecho/wt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

worktrees (wt) 🌳

A friendly CLI tool for managing git worktrees with intuitive commands.

Why?

Git worktrees are powerful but the commands aren't very intuitive. This tool provides a simple, user-friendly interface for common worktree operations.

Installation

Quick install (prebuilt binary):

curl -L https://github.com/elithecho/wt/releases/download/v0.1/worktree -o worktree
chmod +x worktree
sudo mv worktree /usr/local/bin/

Or build from source:

git clone https://github.com/elithecho/wt.git
cd wt
make install

Set up shell integration (required for directory changing):

worktree install
source ~/.zshrc  # or ~/.bashrc for bash

This installs the wt shell function that enables automatic directory changing.

Add .worktrees/ to global gitignore (recommended):

git config --global core.excludesfile ~/.gitignore
echo '.worktrees/' >> ~/.gitignore

Commands

wt add <name> [branch-or-start-point]

Create a new worktree in the .worktrees/ directory. The second argument is resolved in this order:

  1. An existing local branch whose leaf name matches <name> — the worktree is attached to it.
  2. Anything git can resolve to a commit — a local branch, a remote-tracking ref such as origin/main, a tag, or a SHA — is used as the start point, and the new branch is named after the worktree.
  3. Anything else is taken as the name of a new branch to create from HEAD.

With no second argument, a new branch named after the worktree is created from HEAD.

wt add feature-auth                                    # Creates .worktrees/feature-auth with branch "feature-auth"
wt add file-assets-phase feature/file-assets-phase     # Attaches existing branch "feature/file-assets-phase"
wt add hotfix main                                     # Creates branch "hotfix" starting from "main"
wt add feat-x origin/main                              # Creates branch "feat-x" starting from (and tracking) origin/main
wt add release-prep v1.0.0                             # Creates branch "release-prep" starting from tag v1.0.0

Branching off a remote needs the worktree name first — wt add feat-x origin/main, not wt add origin/main (and not wt add refs/remotes/origin/main). wt refuses to create any local branch named after a ref: one whose first path segment is a remote name, or one that is a fully qualified refs/... ref. Git resolves refs/heads/ before refs/remotes/, so a local branch called origin/main would shadow the remote-tracking ref and silently redirect every later git log origin/main or git rebase origin/main to a stale commit.

As a start point — the second argument — refs/remotes/origin/main is accepted and equivalent to origin/main.

wt add starts the branch at whatever you last fetched, so git fetch first.

wt list (aliases: ls, l)

List all worktrees with their paths, branches, and status.

wt list

wt switch <name> (aliases: s, cd, goto, go)

Navigate to a worktree by name. Automatically changes directory with shell integration.

wt switch feature-auth
wt s feature-auth        # Short alias

wt remove <name> (aliases: rm, delete, del)

Remove a worktree by name. The worktree must be clean (no uncommitted changes) unless --force is used.

wt remove feature-auth
wt rm feature-auth
wt remove --force feature-auth  # Force removal of a dirty or untracked worktree

wt promote <name>

Promote a worktree's branch so it becomes the one checked out in the main working path. The previous main branch is left in place as an ordinary branch (not checked out anywhere), and the promoted worktree directory is removed. Both worktrees must be clean unless --force is used.

wt promote feature-auth
wt promote --force feature-auth  # Promote even with uncommitted changes (may be lost)

wt original (aliases: og, main)

Navigate back to the main/original worktree.

wt og

wt clean (aliases: prune)

Clean up stale worktree references for directories that no longer exist.

wt clean

Shell Integration

After installation, run worktree install to automatically set up shell integration for your shell (bash/zsh/fish). This creates a wt function that intercepts navigation commands and handles directory changing automatically.

Usage Examples

# Create a new feature worktree (creates .worktrees/feature-login)
wt add feature-login

# List all worktrees
wt list

# Switch to the feature worktree (automatically changes directory)
wt s feature-login

# Go back to main
wt og

# Remove the feature worktree when done
wt rm feature-login

# Clean up any stale references
wt clean

Features

  • 🚀 Simple commands - Intuitive interface over git worktree
  • 📁 Organized storage - Worktrees stored in .worktrees/ directory
  • 🔍 Smart navigation - Find worktrees by name, not full path
  • 🏠 Quick return - Easy navigation back to main worktree
  • 🧹 Cleanup - Automatic cleanup of stale references
  • 🎨 Pretty output - Clean, readable status display

License

MIT

About

No description, website, or topics provided.

Resources

Stars

3 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors