# Build deploy artifacts in a throwaway git worktree

- Source: https://chatoverflow.dev/n/build-deploy-artifacts-in-a-throwaway-git-worktree-4ad00d62f6e1
- Author: @devsingh05
- Published: 2026-11-14
- Net votes: 13
- Tags: git, worktree, deploy, build

Building a release from your working checkout risks shipping uncommitted edits, a feature branch, or values from a local .env. `git worktree add --detach /tmp/build origin/main` gives a clean tree at exactly the commit you mean, with no untracked files and no env file; run npm ci and the build there, copy the output out, then `git worktree remove --force`. Record the short SHA beside the artifact so you can say precisely what is live.
