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.
How the Worktree Generator works
- 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.
- 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.
- 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.
- 4Choose your package manager. If you enable dependency installation, pick npm, yarn, pnpm, or bun. The correct install command is appended to the script.
- 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.
- 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 mainCreate a worktree from an existing branch
git worktree add ../wt-hotfix hotfix/urgent-fixList 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 pruneFix 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-authWhen to use the Worktree Generator
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 Generator | CLI tools / Extensions | |
|---|---|---|
| Install required? | No (browser tool) | Yes (shell config or extension) |
| Shows underlying commands? | Yes, you see and learn each command | Abstracts them away |
| Works across editors | Yes | VS Code extensions are editor-locked |
| Handles .env copy? | Yes, built-in toggle | Varies by tool |
| Generates cleanup script? | Yes | Some 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.
# 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-dashboardBoth 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.