{
  "id": 10829934,
  "title": "Why coding agents should work on a copy of your repo",
  "url": "https://urgent.news/2026/09/30/why-coding-agents-should-work-on-a-copy-of-your-repo",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-09-30T01:53:19.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/adityagoyal009/why-coding-agents-should-work-on-a-copy-of-your-repo-1l7e"
  },
  "original_language": "en",
  "account": "When using a coding agent, it is crucial to work on a copy of your repository on its own branch. This ensures that the agent's modifications do not affect your working files until you have reviewed the changes and merged them yourself. Git worktrees provide an easy solution for this purpose, allowing for multiple separate working directories within a single repository, each on a different branch.\n\nWorking on a copy of your repository with a separate branch offers several benefits. Mixed changes are avoided, as the agent's edits and your half-finished work remain in distinct sets. The agent changes a file independently of your editing, preventing disruptions in your development environment. Reviewing the agent's work becomes more manageable, as there is a clear before-and-after diff, making it easier to understand the changes made. Undoing undesirable results is also simpler since discarding the agent's changes won't impact your own work.\n\nGit worktrees function by creating additional working directories attached to the same repository. Each worktree has its own branch, files on disk, and staging area, while sharing the underlying commit history. This sharing allows for real-time visibility and comparison of changes between worktrees without the need for additional cloning or pushing/pulling operations.\n\nTo create a worktree and branch for an agent's task, use the command `git worktree add ../myproject-fix-login -b agent/fix-login`. To view the existing worktrees, run `git worktree list`. Review the changes from the main directory when the agent has finished working, using `git diff main...agent/fix-login`. If satisfied, merge the agent's changes with `git merge agent/fix-login` and remove the worktree directory with `git worktree remove ../myproject-fix-login`. Additionally, use `git branch -d agent/fix-login` to delete the branch once it is no longer needed.\n\nHowever, be aware of potential pitfalls. Files not tracked by Git are not copied to the new worktree, so you may need to run an install step and provide any local configuration the project requires. Avoid copying secrets into an agent-accessible directory and ensure you have the necessary permissions and sandboxes in place for safety. Create and remove worktrees promptly to optimize disk space and manage shared machine resources effectively. Keep the main branch up-to-date with `git pull` to prevent stale branches, and test the workflow manually before relying on it.\n\nWhile worktrees provide isolation from your working files, they do not restrict the agent's overall capabilities on your computer. Agents can still access other folders, use the network, and interact with anything your user account can access. For enhanced protection, consider limiting tools and permissions, implementing approval processes for risky commands, and using containers or virtual machines for stronger separation. By using worktrees for organization and review, combined with appropriate permissions and sandboxes, you can effectively manage the workflow involving coding agents and maintain control over your machine resources.",
  "summary": "A coding agent should work on its own copy of your repository, on its own branch, so that nothing it does touches your working files until you have read the diff and merged it yourself. Git worktrees are the simplest way to do this: one repository, several separate working directories, each on a different branch. This guide explains what goes wrong without isolation, how worktrees work, the…",
  "key_points": [
    "Coding agents should work on a copy of your repository on a separate branch.",
    "Git worktrees enable multiple working directories within a single repository for agent tasks.",
    "Review agent changes with git diff before merging and removing the worktree directory."
  ],
  "editors_take": "Using a coding agent on a copy of your repository with a separate branch allows for safer collaboration, easier review, and better control over changes, reducing disruptions and potential security risks.",
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}