Sandbox
@raghavpillai/branchlet

Git worktree CLI for agent workflows

Branchlet is a CLI for creating and managing Git worktrees from an interactive menu or direct commands. It supports project and global config, copy rules for files like `.env*` and `.vscode/**`, and post-create commands such as installs or editor launchers. The CLI can also run non-interactively with flags for worktree name, source branch, and new branch name.

496 starsโ€ข28 forksโ€ขTypeScriptโ€ขUpdated 5mo ago
Who it's for

Builders who manage separate branches and worktrees while using agent-driven coding tools.

What it delivers

You can create and organize worktrees without manually repeating Git and setup steps.

What it does

Interactive worktree menu

Run `branchlet` to open a menu for creating, listing, deleting worktrees, and changing settings.

Direct commands

Use `branchlet create`, `branchlet list`, `branchlet delete`, or `branchlet settings` to jump straight to one action.

Non-interactive creation

Pass `-n`, `-s`, and `-b` flags to create worktrees from scripts without answering prompts.

Project and global config

Reads `.branchlet.json` in the repo root first, then `~/.branchlet/settings.json` for shared defaults.

File copy rules

Copies matching files into new worktrees with `worktreeCopyPatterns` and skips paths with `worktreeCopyIgnores`.

Post-create commands

Runs configured commands after creating a worktree, such as `npm install` or `code .`.

Worktree path templates

Uses template variables like `$BASE_PATH`, `$WORKTREE_PATH`, `$BRANCH_NAME`, and `$SOURCE_BRANCH` to name new worktrees.

Delete branch with worktree

Can remove the associated branch too, with safety checks for unpushed commits and uncommitted changes.

How to get it

  1. 1Run
    npm install -g branchlet
  2. 2Run Branchlet in any Git repository
    branchlet
  3. 3Navigate to your Git repository
    cd my-project
  4. 4Start Branchlet
    branchlet

README

๐ŸŒณ Branchlet

npm version license

A interactive CLI tool for creating and managing Git worktrees with an easy to use interface.

Branchlet Demo

Features

  • Quick Commands: Jump directly to specific actions via command line
  • Smart Configuration: Project-specific and global configuration support
  • File Management: Automatically copy configuration files to new worktrees
  • Post-Create Actions: Run custom commands after worktree creation

Installation

npm install -g branchlet

Quick Start

Run Branchlet in any Git repository:

branchlet

This opens an interactive menu where you can:

  • Create new worktrees
  • List existing worktrees
  • Delete worktrees
  • Configure settings

Commands

Interactive Menu (Default)

branchlet

Opens the main menu with all available options.

Direct Commands

branchlet create    # Go directly to worktree creation
branchlet list      # List all worktrees
branchlet delete    # Go directly to worktree deletion
branchlet settings  # Open settings menu

Options

branchlet --help     # Show help information
branchlet --version  # Show version number
branchlet -m create  # Set initial mode

Non-Interactive (Scriptable) CLI

Pass flags to skip the interactive prompts entirely. The three core concepts map directly to flags:

FlagDescription
-n, --name <name>Worktree directory name
-s, --source <branch>Source branch to create from
-b, --branch <branch>New branch name (defaults to -n when omitted)
# Create a worktree โ€” new branch defaults to the worktree name
branchlet create -n my-feature -s main

# Create a worktree with an explicit branch name different from the directory
branchlet create -n ticket-3121-backend -s main -b feature/ticket-3121

# Create multiple sibling worktrees from the same source branch
# (each gets its own branch, so there's no checkout conflict)
branchlet create -n digit3121-backend  -s main -b feat/digit3121-backend
branchlet create -n digit3121-frontend -s main -b feat/digit3121-frontend

# List worktrees as JSON
branchlet list --json

# Delete a worktree by name
branchlet delete -n my-feature

# Force-delete a worktree by path
branchlet delete -p /path/to/worktree -f

Successful create output:

/path/to/worktree
  source: main
  branch: my-feature

Configuration

Branchlet looks for configuration files in this order:

  1. .branchlet.json in your repo's root (project-specific)
  2. ~/.branchlet/settings.json (global configuration)

Configuration Options

Create a .branchlet.json file in your project root or configure global settings:

{
  "$schema": "https://raw.githubusercontent.com/raghavpillai/branchlet/main/schema.json",
  "worktreeCopyPatterns": [".env*", ".vscode/**"],
  "worktreeCopyIgnores": ["**/node_modules/**", "**/dist/**", "**/.git/**"],
  "worktreePathTemplate": "$BASE_PATH.worktree",
  "postCreateCmd": ["npm install", "npm run db:generate"],
  "terminalCommand": "code .",
  "deleteBranchWithWorktree": true
}

Configuration Fields

  • worktreeCopyPatterns: Files/directories to copy to new worktrees (supports glob patterns)

    • Default: [".env*", ".vscode/**"]
    • Examples: ["*.json", "config/**", ".env.local"]
  • worktreeCopyIgnores: Files/directories to exclude when copying (supports glob patterns)

    • Default: ["**/node_modules/**", "**/dist/**", "**/.git/**", "**/Thumbs.db", "**/.DS_Store"]
  • worktreePathTemplate: Template for worktree directory names

    • Default: "$BASE_PATH.worktree"
    • Variables: $BASE_PATH, $WORKTREE_PATH, $BRANCH_NAME, $SOURCE_BRANCH
    • Examples: "worktrees/$BRANCH_NAME", "$BASE_PATH-branches/$BRANCH_NAME"
  • postCreateCmd: Commands to run after creating a worktree. Runs in the new worktree directory.

    • Default: []
    • Examples: ["npm install"], ["pnpm install", "pnpm build"]
    • Variables supported in commands: $BASE_PATH, $WORKTREE_PATH, $BRANCH_NAME, $SOURCE_BRANCH
  • terminalCommand: Command to open terminal/editor in the new worktree. Runs in the new worktree directory.

    • Default: ""
    • Examples: "code .", "cursor .", "zed ."
  • deleteBranchWithWorktree: Whether to also delete the associated git branch when deleting a worktree

    • Default: false
    • When enabled, deleting a worktree will also delete its branch (with safety checks)
    • Shows warnings for branches with unpushed commits or uncommitted changes

Template Variables

Available in worktreePathTemplate, postCreateCmd, and terminalCommand:

  • $BASE_PATH: Base name of your repository
  • $WORKTREE_PATH: Full path to the new worktree
  • $BRANCH_NAME: Name of the new branch
  • $SOURCE_BRANCH: Name of the source branch

Usage Examples

Basic Workflow

  1. Navigate to your Git repository

    cd my-project
    
  2. Start Branchlet

    branchlet
    
  3. Create a worktree

    • Select "Create new worktree"
    • Enter directory name (e.g., feature-auth)
    • Choose source branch (e.g., main)
    • Enter new branch name (e.g., feature/authentication)
    • Confirm creation

Project-Specific Configuration

Create .branchlet.json in your project:

{
  "$schema": "https://raw.githubusercontent.com/raghavpillai/branchlet/main/schema.json",
  "worktreeCopyPatterns": [
    ".env.local",
    ".vscode/**",
    "package.json",
    "tsconfig.json"
  ],
  "worktreePathTemplate": "worktrees/$BRANCH_NAME",
  "postCreateCmd": [
    "npm install",
    "npm run db:populate"
  ],
  "terminalCommand": "code .",
  "deleteBranchWithWorktree": true
}

Requirements

  • Node.js 20.0.0 or higher
  • Git installed and available in PATH
  • Operating system: macOS, Linux, or Windows

License

MIT

Files in the repo

Repository payloadโ€ข14 top-level entries
  • .github
  • assets
  • scripts
  • src
  • tests
  • .gitignore
  • biome.json
  • bun.lock
  • bunfig.toml
  • LICENSE
  • package.json
  • README.md
  • schema.json
  • tsconfig.json

Discussion (0)

Ask about usage, or say what you built with it

Sign in to join the discussion.

No comments yet. Be the first to say what this is good for.

More tools

JuliusBrussee/
caveman

๐Ÿชจ why use many token when few token do trick โ€” Claude Code skill that cuts 65% of tokens by talking like caveman

105k
1 add
MemPalace/
mempalace

The best-benchmarked open-source AI memory system. And it's free.

59k
stablyai/
orca

Orca is the ADE for working with a fleet of parallel agents. Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

66k

A cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode, OpenClaw, Grok Build & Hermes Agent. Only official website: ccswitch.io

132k

Never stop coding. Free MIT AI gateway: one endpoint, 352 providers (150+ free), 1200+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 550+ contributors

64k
headroomlabs-ai/
headroom

Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.

71k