@dentology/git-worktree
v0.2.0
Published
Create a git worktree from origin/main with one command. Optionally shares node_modules and .env with the main worktree.
Readme
@dentology/git-worktree
wt — create a git worktree from origin/main with one command.
By default it symlinks node_modules, apps/dentology/.env, and apps/dentology/database/.env.prod.local from your main worktree when those files exist, so you don't need to wait for bun install every time you start work on a new branch.
Install
npm i -g @dentology/git-worktreeOr run without installing:
npx @dentology/git-worktree --helpUsage
wt [<name>] [--branch=<name>] [--nodeModules=shared|separate] [--from=<ref>]
wt help | --help | -hIf no branch is provided, you'll be prompted to pick one from your recently-created local branches (or type a new name).
<name> defaults to a sanitized version of the branch name (e.g. feature/x becomes feature-x).
The new worktree is created at <repo-root>/worktrees/<name>.
Options
| Option | Default | Description |
| ---------------------------- | ------------- | ------------------------------------------------------------------------------------------------------------------ |
| -b, --branch <name> | prompt | Branch to create. If omitted, you pick from recent branches. |
| -n, --nodeModules <mode> | shared | shared symlinks node_modules from the main worktree (fast). separate runs bun install in the new worktree. |
| -f, --from <ref> | origin/main | Start point for the new branch. |
| -h, --help | | Show help. |
Examples
wt fix-task-analytics --branch=task/analytics
wt --nodeModules=separate
wt feature-x --branch=feature/x --from=origin/mainRequirements
- Run from inside a git checkout.
- Bun is only required when using
--nodeModules=separate.
Notes
- Add
worktrees/to your repo's.gitignoreso worktrees don't pollute git status. - When you change
package.jsonor the lockfile, switch to--nodeModules=separate(or remove thenode_modulessymlink andbun install) to pick up the new state.
Local development (Dentology monorepo)
From the monorepo root:
bun run wt --helpThis runs the source directly via Bun without needing a build.
Publishing a release
One-time setup:
npm whoami(ornpm login) — you must be logged in.- The
@dentologyorg must exist on npmjs.com and you must be a member with publish rights. (The package already has"publishConfig": { "access": "public" }, so you don't need--access public.)
For each release, from the monorepo root:
# 1. Bump the version
( cd tools/git-worktree && npm version patch ) # or: minor / major
# 2. Build + publish in one go
bun run wt:publishbun run wt:publish runs the Nx target git-worktree:publish, which depends on build (so it always rebuilds first) and runs npm publish from dist/tools/git-worktree. You can also invoke it directly:
nx run git-worktree:publishOptional preview before publishing:
( cd dist/tools/git-worktree && npm pack --dry-run )Why publish from dist/tools/git-worktree? Nx's @nx/js:tsc build copies the package.json and README.md there and emits the compiled src/cli.js (with the shebang). Publishing from the source folder would ship TypeScript that nobody can run — the Nx target handles this for you.
Verify:
npm view @dentology/git-worktree
npx @dentology/git-worktree --helpNotes:
- npm rejects re-publishing the same version — bump first, or use
npm publish --tag nextfor a pre-release without movinglatest. - If your account requires 2FA,
npm publishwill prompt for an OTP (or pass--otp 123456). - Quick rollback within ~72h:
npm unpublish @dentology/git-worktree@<version>. After that window, onlynpm deprecateis allowed.
