Run Tests in Parallel Using a Worktree

Execute long-running test suites or builds in one worktree while continuing development in another.

worktreetestingbuildworkflowparallel development

When to use

Your test suite takes several minutes to run, and you want to continue coding instead of waiting. A separate worktree lets you run tests in the background without blocking your workflow.

Pre-flight

  • Commit or stash any changes you want to test (worktrees share the Git history but not uncommitted changes).
  • Ensure you have enough system resources to run tests and your editor simultaneously.

Steps

  1. Create a worktree for testing, pointing at the branch or commit you want to verify.

    git worktree add ../test-runner main

    Or test your current feature branch:

    git worktree add -b test-feat ../test-runner HEAD
  2. Open a new terminal and navigate to the test worktree.

    cd ../test-runner
  3. Install dependencies if needed and run your test suite.

    npm ci
    npm test
  4. Continue working in your main directory while tests run in the other terminal.

  5. When finished, clean up the test worktree.

    cd ../your-main-repo
    git worktree remove ../test-runner

Verification

  • Tests complete in the separate terminal without interrupting your main workflow.
  • git worktree list confirms the test worktree is removed after cleanup.

Pro tip: Persistent test worktree

Keep a dedicated test worktree around for frequent use:

# Create once
git worktree add ../project-tests main

# Update to latest before each test run
cd ../project-tests
git checkout main
git pull origin main
npm test

Follow-up

  • Consider setting up a CI pipeline if you find yourself doing this frequently.
  • Use tmux or terminal splits to monitor test output while coding.

Related scenarios