A small Git worktree helper that creates and cleans up project worktrees using a repo-local .worktree.yaml config.
- English | 한국어
- Binary names:
swtandsimple-worktree - Creates worktrees under
.worktrees/by default - Copies local-only files such as
.envinto new worktrees - Runs optional setup/cleanup hooks
- Node.js 18+
- Git
- pnpm if you want to use the examples below (
pnpm dlx,pnpm exec)
If pnpm is not enabled yet:
corepack enable- Node.js 22.22.x, recommended
22.22.3 - pnpm
10.32.1
This repository includes .nvmrc and .node-version for development. The higher Node version is for maintaining/building this package; installing and using the published CLI can work on lower Node versions as noted above.
Run this in the repository where you want to use worktrees:
pnpm dlx @jayjnu/simple-worktree initOr with npm:
npx @jayjnu/simple-worktree initReview and commit the generated config:
git add .worktree.yaml
git commit -m "add worktree config"Create a worktree:
pnpm dlx @jayjnu/simple-worktree create feature/my-taskWith npm:
npx @jayjnu/simple-worktree create feature/my-taskClean it up later:
pnpm dlx @jayjnu/simple-worktree cleanup feature/my-taskWith npm:
npx @jayjnu/simple-worktree cleanup feature/my-taskCommit
.worktree.yamlbefore creating child worktrees if you want to runcleanupfrom inside a child worktree without passing--config.
Project-local install:
pnpm add -D @jayjnu/simple-worktree
pnpm exec swt create feature/my-task
pnpm exec swt cleanup feature/my-taskGlobal install:
pnpm add -g @jayjnu/simple-worktree
swt create feature/my-task
swt cleanup feature/my-taskGlobal install with npm:
npm install -g @jayjnu/simple-worktree
swt create feature/my-task
swt cleanup feature/my-taskswt init creates this starter config:
worktreeDir: .worktrees
copyFiles: []
hooks:
postCreate: []
preCleanup: []
postCleanup: []A more realistic example:
worktreeDir: .worktrees
copyFiles:
- backend/.env
- frontend/.env.local
hooks:
postCreate:
- pnpm install
preCleanup: []
postCleanup: []Relative directory under the primary worktree where new worktrees are created. Defaults to .worktrees.
Unsafe values such as .., ., and .git/** are rejected.
Relative files copied from the primary worktree into the newly created worktree.
Use this for files that are intentionally not committed, for example:
.env.env.local- local tool config
Missing files are skipped with a warning.
Shell commands run through the current platform's default shell.
postCreate: runs inside the new worktree aftercopyFilesare copiedpreCleanup: runs inside the target worktree before removalpostCleanup: runs inside the primary worktree after removal
swt init [--force] [--config .worktree.yaml]Writes a starter config. Existing config files are not overwritten unless --force is passed.
swt create [--enter] [--config .worktree.yaml] <branch-name> [base-ref]Creates <worktreeDir>/<sanitized-branch-name> under the primary worktree.
Behavior:
- If
<branch-name>already exists, it checks out that branch in the new worktree. - Otherwise, it creates the branch from
[base-ref]or the invoking worktree'sHEAD. - If
postCreatefails, the newly created worktree and branch are rolled back. --enteris accepted for compatibility, but a child process cannot change your parent shell directory. The CLI prints a copy-pasteablecdhint instead.
swt cleanup [--config .worktree.yaml] [--keep-branch] [--force] [worktree-path-or-branch]Removes a Git worktree.
Behavior:
- With no target, removes the current worktree context.
- Refuses to remove the primary repository worktree.
- Deletes the worktree branch by default.
- Pass
--keep-branchto preserve the branch. - Pass
--forceto forward force deletion togit worktree remove --forceandgit branch -D.
pnpm install
pnpm run lint
pnpm test
pnpm run pack:dry-runTo use the current checkout as a local binary before publishing:
pnpm run build
pnpm link --global
swt --help- No project-local
.shscript is required. - The package is implemented in TypeScript.
- Core worktree behavior is separated from Node/OS adapters so it can be tested with mock ports.