Dev Encyclopedia
ArticlesToolsAbout

Get notified when new content drops

No spam. Just new articles, tools, and updates straight to your inbox.

Dev Encyclopedia

A reference for builders

Content

  • Articles
  • Tools
  • About
  • Contact

Connect

  • support@devencyclopedia.com
  • RSS Feed

Legal

  • Privacy Policy
  • Terms of Service
  • Disclaimer

© 2026 Dev Encyclopedia

Back to top ↑
  1. Home
  2. /
  3. Tools
  4. /
  5. Worktree Generator
Free · Live

Stop Googling the Git Worktree Syntax Every Time

Answer three questions, get the exact commands to create, configure, and clean up a worktree. Copy, paste, done.

Zeeshan Tofiq

Zeeshan Tofiq

Full Stack Developer

How the Worktree Generator works

  1. 1Enter your branch details. Specify the base branch you want to branch from (usually main or develop) and the name for your new feature branch.
  2. 2Get an auto-generated directory name. The tool converts your branch name into a clean, consistent directory name prefixed with wt- so worktrees are easy to spot in your filesystem.
  3. 3Toggle .env file copying. Since .env files are gitignored, new worktrees won't have them. Enable this toggle and the generator adds cp commands for .env and .env.local to your script.
  4. 4Choose your package manager. If you enable dependency installation, pick npm, yarn, pnpm, or bun. The correct install command is appended to the script.
  5. 5Copy the generated script. The tool assembles all commands in the correct order: worktree creation, directory change, env copy, dependency install. One click copies everything to your clipboard.
  6. 6Generate cleanup commands separately. Switch to the Cleanup tab when a worktree's branch has been merged. Enter the directory and branch name to get the removal and prune commands.

What each generated command does

The generator outputs standard Git and shell commands. Here is what each one does and why it matters.

git worktree add ../dir -b branch baseCreates a new working directory at ../dir, checks out a new branch from base. The -b flag creates the branch; omit it to check out an existing branch.
cp ../<main>/.env .envCopies your environment variables into the new worktree. Without this, the app won't start because .env is gitignored and not part of the checkout.
npm install (or yarn/pnpm/bun)Each worktree has its own node_modules directory. Dependencies must be installed fresh in every new worktree, even though the lockfile is shared.
git worktree remove ../dirRemoves the worktree directory and its metadata from .git/worktrees. Fails if there are uncommitted changes (use --force to override).
git branch -d branchDeletes the branch after removal. Uses -d (safe delete) which refuses if the branch hasn't been merged. Use -D to force-delete an unmerged branch.
git worktree pruneCleans up stale worktree references in .git/worktrees. Run this if you manually deleted a worktree directory instead of using git worktree remove.

Git worktree command reference

Every git worktree subcommand you need, with examples covering common edge cases.

Create a worktree with a new branch

git worktree add ../wt-feat-auth -b feat/auth main

Create a worktree from an existing branch

git worktree add ../wt-hotfix hotfix/urgent-fix

List all active worktrees

git worktree list
# /home/user/my-project        abc1234 [main]
# /home/user/wt-feat-auth      def5678 [feat/auth]
# /home/user/wt-feat-dashboard  ghi9012 [feat/dashboard]

Remove a worktree and clean up

git worktree remove ../wt-feat-auth
git branch -d feat/auth
git worktree prune

Fix a stale lock (worktree directory was deleted manually)

# If you deleted the directory without "git worktree remove":
git worktree prune

# If a lock file is blocking a new worktree:
git worktree unlock ../wt-feat-auth

When to use the Worktree Generator

ScenarioWhat to enter
Parallel AI agent sessionsOne worktree per agent. Base: main, Branch: the feature each agent is working on.
Hotfix while a feature is in progressBase: main (or production), Branch: hotfix/issue-name. Keep your feature branch untouched in the original directory.
Reviewing a teammate's PR locallyBase: the PR's branch (no -b flag needed). Omit the new branch name and use the existing remote branch.
Running two dev servers side by sideCreate two worktrees from different branches, enable dependency install, and run each server in its own terminal.
Testing a migration against the current versionOne worktree on main (current), one on the migration branch. Compare behavior side by side.
Batch cleanup after a sprintSwitch to the Cleanup tab. Enter each finished worktree's directory and branch to generate removal commands.

Frequently Asked Questions

What does the Worktree Command Generator do?

It generates copy-pastable shell commands for creating and cleaning up Git worktrees. You fill in your branch name and preferences (whether to copy .env files, which package manager to use), and the tool assembles the exact commands in the right order.

Nothing is saved, nothing is sent anywhere. The tool runs entirely in your browser.

How is this different from git-worktree-runner (gtr) or VS Code extensions?
Worktree GeneratorCLI tools / Extensions
Install required?No (browser tool)Yes (shell config or extension)
Shows underlying commands?Yes, you see and learn each commandAbstracts them away
Works across editorsYesVS Code extensions are editor-locked
Handles .env copy?Yes, built-in toggleVaries by tool
Generates cleanup script?YesSome do, most do not

Use this generator when you want to understand and control the commands yourself. Use a CLI wrapper when you want a single command that does everything behind the scenes.

Is my data sent anywhere?

No. The tool runs 100% in your browser using client-side JavaScript. No API calls, no server processing, no data stored. Your branch names and configuration never leave your machine.

How do I use worktrees with multiple AI coding agents?

Create one worktree per agent session. Each agent gets its own working directory with its own branch, so file writes from one agent never conflict with another.

bash
# Terminal 1: Agent working on auth feature
git worktree add ../wt-feat-auth -b feat/auth main
cd ../wt-feat-auth

# Terminal 2: Agent working on dashboard
git worktree add ../wt-feat-dashboard -b feat/dashboard main
cd ../wt-feat-dashboard

Both agents share the same Git history and object database, but each has independent files. When both are done, merge each branch into main separately.

Why aren't .env files in my new worktree by default?

Git worktrees share the .git directory but create a fresh checkout of the branch's tracked files. Since .env and .env.local are in .gitignore (as they should be), they exist only in the directory where you originally created them.

The generator handles this with the "Copy .env files" toggle, which adds a cp command to your setup script so the new worktree gets a copy of your environment variables.

Related reading

Tutorial

Git Worktrees for Parallel AI Coding Agents: The Complete 2026 Workflow

The full tutorial on setting up worktrees for multi-agent development, with a decision framework for when to use them.

Reference

Claude Code Cheatsheet: Every Command, Hook, Subagent, and Shortcut

Complete reference for Claude Code including the native worktree support and subagent parallel workflows.

Zeeshan Tofiq

Zeeshan Tofiq

Full Stack Developer

Full stack developer with over 6 years of experience building production applications. Writes practical guides on JavaScript, TypeScript, React, Node.js, and cloud infrastructure. Focused on helping developers solve real problems with clean, maintainable code.

Enjoyed this article?

Get practical dev guides, tool updates, and new articles delivered straight to your inbox. No spam, unsubscribe anytime.

Fill in the branch name above to generate your commands.