iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
With one Git worktree per task, each coding task gets its own working directory, usually paired with its own branch. The directories stay attached to one repository: they share repository data, while each worktree has its own checked-out files and some Git state. That keeps task edits from colliding in a single checkout, but it does not isolate everything the code might use at runtime.
What does “one worktree per task” mean?
A Git worktree is a working directory linked to a repository. The main worktree is the original checkout; the repository can also have linked worktrees. As the Git documentation puts it: “A git repository can support multiple working trees, allowing you to check out more than one branch at a time.”
A linked worktree is not a separate clone. It shares repository data with the main worktree, but has its own checked-out files and per-worktree state such as its HEAD and index. In practice, a task-specific directory plus a distinct branch makes it clear where that task’s edits belong and how they can be reviewed or integrated.
Where do a coding agent’s changes go?
The agent edits files in the working directory where it is running. If it is started in a task worktree, those file changes are in that worktree, and Git reports them against the branch or commit checked out there. Before asking an agent to edit, verify its working directory and the worktree’s status so you know which task it will affect.
#1 Best Overall
A worktree separates checked-out files and certain Git state; it is not a complete runtime or security sandbox. Running servers, databases, secrets, package caches, and other services may still be shared, depending on how the development environment is configured.
How do you create a separate worktree and branch?
For a task that will produce changes, create a new branch and check it out in a new directory. Choose the starting point that matches your repository’s actual base branch.
-
From the repository, run
git worktree add -b feature/task-name ../task-name main. Replacefeature/task-namewith a unique branch name,../task-namewith the desired directory, andmainwith the intended starting branch or commit.Free tools Windows power users keep installed
One-click scans. No signup required.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy. -
Change into
../task-name, then rungit statusto confirm the branch and working tree before editing.Rank #2
-
Run the coding agent from that directory and verify its working directory if the agent interface exposes it.
-
When the work is ready, inspect the diff and status, then use your normal review and merge process to integrate the task branch.
The command form and behavior are documented in the Git worktree reference. Git can also create a worktree without a new branch, including a detached worktree for experiments or testing. If you use branches for concurrent tasks, give each task a distinct branch: Git refuses by default to check out a branch that is already in use in another worktree.
What is shared, and what needs separate setup?
Because linked worktrees belong to the same repository, they share repository data rather than maintaining independent copies of all Git history. Each has a distinct working directory and worktree-specific state. This is useful for parallel editing, but it does not mean every file or dependency is duplicated or automatically available.
In a linked worktree, the top-level .git entry is a file pointing to repository metadata, not a complete independent .git directory. Scripts, containers, or tools that mount only the linked directory may not be able to reach the metadata path that file references. Keep the relevant repository layout accessible to those tools.
Ignored local files are another setup edge case. A manually created Git worktree does not automatically receive ignored files such as local environment configuration. Handle those according to your team’s setup process, and check which local services or credentials the task actually needs.
How Codex app-managed worktrees differ
Codex app-managed worktrees have product-specific behavior; these details are not rules for ordinary Git worktrees. OpenAI’s Codex worktrees guide says managed worktrees are typically dedicated to one chat, while permanent worktrees are intended for longer-lived projects and can host multiple chats.
For local managed worktrees, the guide says Codex creates them beneath $CODEX_HOME/worktrees by default, though the root can be changed in Settings. A managed worktree starts from the selected branch’s HEAD and is detached. If that selected branch has uncommitted changes, Codex applies those changes to the worktree.
Copying ignored files into a local managed worktree
For local ChatGPT desktop app managed worktrees, OpenAI documents a .worktreeinclude file for specifying ignored paths to copy, such as .env or local configuration. Codex copies matching ignored files, skips source symlinks, and does not overwrite files already present. This behavior is documented for local app-managed worktrees, not for remote worktrees or worktrees created manually from the command line.
Moving a chat between Local and Worktree
The Codex guide says a chat can be handed between Local and Worktree, with the app handling the Git operations. Ignored files do not move in a handoff unless copied into a local managed worktree with .worktreeinclude. Because Git does not allow the same branch to be checked out in two worktrees at once by default, use the app’s handoff flow rather than trying to check out that branch simultaneously in both locations.
Managed-worktree retention
The guide documents a default retention setting of the most recent 15 Codex-managed worktrees; the setting can be changed or disabled, so it is a product default rather than a Git limit. It also says Codex saves a snapshot before automatically deleting a managed worktree and can offer restoration when the chat is reopened. Check the current app settings and guide if this retention behavior matters to your workflow.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →How do you inspect and clean up worktrees?
Git provides commands to inspect registered worktrees and remove or repair their administrative records. Use them deliberately so you do not discard work you still need.
Best Value
-
git worktree listshows the worktrees associated with the repository. -
git worktree remove <path>removes a linked worktree. Git expects it to be clean by default; review or preserve uncommitted and untracked work before removal. -
If you manually deleted a worktree directory,
git worktree pruneclears stale administrative data for paths that no longer exist. It is not a substitute for removing a worktree that is still present.Recommended Free Tools
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy. -
If you manually moved a worktree,
git worktree repaircan repair its administrative links when needed.
These commands and safeguards are covered in the Git reference. Avoid force-removing a worktree unless you understand what Git’s safety checks are protecting.
When is one worktree per task useful?
Use a task worktree when separate checked-out directories and branches will make concurrent work easier to manage—for example, when an agent should work on one change while you keep another task open in the main checkout. A second clone is a different choice: it creates another repository checkout rather than another working tree linked to the same repository. The sources do not establish a measured disk-space or performance advantage for worktrees over clones, so choose based on workflow and setup needs rather than assumed savings.
Keeping all tasks in one shared checkout offers less directory separation: switching branches or editing the same files there can disrupt another task. Worktrees avoid that particular collision by providing separate checkouts, while still leaving runtime resources and ignored-file setup to your environment. For changes that need review, the task branch gives you a normal Git diff and integration path.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

