Shuna Maekawa / Projects

portree - Git Worktree Server Manager

2026-02-06 · CLI Tool, Go, Git Worktree, TUI, Developer Tools

A CLI tool that automatically manages multiple dev servers per git worktree with automatic port allocation, environment variable injection, and subdomain routing.

Overview

When working on multiple feature branches simultaneously using git worktrees, managing separate dev servers for each branch becomes tedious. You need to manually track ports, configure environment variables, and remember which server is running where.

portree solves this by automatically managing multiple dev servers per git worktree—with hash-based port allocation, environment variable injection, and *.localhost subdomain routing via a built-in reverse proxy.


The Problem

In a typical monorepo setup with frontend and backend services:


Features


Tech Stack


How It Works

┌─────────────────────────────────────────────────────────────┐
│  git repository                                             │
│                                                             │
│  main worktree          feature/auth worktree               │
│  ┌───────────────┐      ┌───────────────┐                   │
│  │ frontend :3100│      │ frontend :3117│                   │
│  │ backend  :8100│      │ backend  :8104│                   │
│  └───────────────┘      └───────────────┘                   │
│         │                      │                            │
└─────────┼──────────────────────┼────────────────────────────┘
          │                      │
    ┌─────▼──────────────────────▼─────┐
    │     portree reverse proxy        │
    │                                  │
    │  :3000  ←  *.localhost:3000      │
    │  :8000  ←  *.localhost:8000      │
    └──────────────────────────────────┘
          │                      │
          ▼                      ▼
  main.localhost:3000    feature-auth.localhost:3000
  main.localhost:8000    feature-auth.localhost:8000
  1. Port allocation — Each service gets a port via FNV32(branch:service) % range. Stable across restarts.
  2. Process management — Services run as child processes with process groups. Logs go to .portree/logs/.
  3. Reverse proxy — One HTTP listener per proxy_port. Routes based on Host header subdomain.
  4. *.localhost — Modern browsers resolve *.localhost to 127.0.0.1 automatically per RFC 6761.

Usage

# Initialize in your project
portree init

# Start services for current worktree
portree up

# Start services for ALL worktrees
portree up --all

# Start the reverse proxy
portree proxy start

# Open the TUI dashboard
portree dash

# Check status
portree ls

TUI Dashboard

Manage all your services from an interactive terminal UI:


Development Highlights


Links