t3code icon indicating copy to clipboard operation
t3code copied to clipboard

dotenv sync for new worktrees

Open Snowy7 opened this issue 8 months ago • 3 comments

When a project uses Git worktrees, new worktrees do not get any local .env* files from the main repo checkout. That creates a rough first-run experience for projects that depend on local env files to boot or run setup commands:

the worktree is created successfully setup commands can fail because required env files are missing the user has to manually copy .env, .env.local, apps/*/.env.local, etc. into every new worktree This feels like a good fit for a small project-scoped workflow improvement rather than a global app setting, since the desired files depend on the specific repo.

A minimal version could be:

  • add a project-scoped dotenv sync config under the existing header Actions control
  • let the user save an explicit allowlist of project-relative dotenv paths
  • when a new worktree is created, copy those files from the main project root into the new worktree before any runOnWorktreeCreate action runs overwrite existing target files in the new worktree
  • optionally expose a manual Sync now action for the current worktree
  • To keep it narrow, I would limit this to files whose basename starts with .env and require relative paths only.

Nice-to-have Inside that modal, a small detect button could scan the workspace for candidate .env* files and add them to the allowlist automatically, while ignoring directories like:

  • .git
  • .turn
  • .next
  • dist
  • build
  • node_modules

This would mainly improve reliability and reduce setup friction for worktree-based flows without changing the core model much: setup actions can depend on env files being present users avoid repeating manual copy steps for each new worktree the behavior stays explicit and project-scoped instead of becoming a generic file-sync feature.

I already have a local implementation draft, but it is larger than your contribution guidelines suggest, so I thought I would open the issue with the PR just in case, maybe you guys want to do it in a different approach.

Snowy7 avatar Mar 10 '26 01:03 Snowy7

Image

maria-rcks avatar Mar 15 '26 21:03 maria-rcks

Maybe not separate feature, but automatic suggestion / precreation of the action when such file is detected in the root project workdir?

Why - it is not immediately obvious that worktrees do not copy the non-indexed files. While it makes sense from how worktrees work, since it is a new concept for many people, it would be nice to have some help from the tool/UI itself.

DocX avatar Mar 16 '26 16:03 DocX

The .env / .env.local copying part here is exactly what caught my attention.

I built local.env around avoiding that manual step. Env requirements live with the code, while the real local-development values are encrypted and synced separately through the CLI.

So when you create another worktree, the intended workflow is basically “sync what this repo needs” rather than maintaining another script that copies ignored files around.

It’s still an early public release, so if you’re still dealing with this I’d genuinely like to know where it breaks down for your setup:

https://github.com/mithatakbulut/local.env

mithatakbulut avatar Aug 19 '26 01:08 mithatakbulut