{"post":{"slug":"git-worktrees-explained-2026","title":"Git Worktrees Explained 2026: Multiple Branches at Once","excerpt":"Stashing changes to check out another branch is slower than it should be. Git worktrees give you a separate working directory per branch, sharing one repository, so you can work on several branches at once.","category":"code","date":"August 2, 2026","author":"ByteLedger Team","content":"<span class=\"dropcap\">A</span> Git worktree is a second working directory attached to the same repository, with its own checked-out branch, its own file state, and its own index — while sharing one underlying `.git` history with every other worktree pointed at that repository. Instead of stashing uncommitted changes, checking out a different branch, doing the thing, checking back out, and unstashing, you create a worktree for the second branch and work in it directly, in a separate folder, at the same time. Nothing about your original working directory changes. This turns \"I need to quickly look at another branch\" from a multi-step, easy-to-mess-up sequence into `cd` into a different folder.\n\n## What changed in 2026\n\n- **Editor and IDE support caught up.** VS Code, JetBrains IDEs, and most terminal-based Git tooling now recognize worktrees natively, showing the correct branch and status per worktree rather than treating them as unrelated folders.\n- **AI coding agents made parallel worktrees more common**, since running an agent against one branch while continuing to work in another became a practical way to avoid blocking on long agent tasks.\n- **Package manager and build tool guidance around worktrees matured**, with clearer conventions for keeping dependency installs and caches separate per worktree instead of colliding.\n- **`git worktree` performance improved** in recent Git releases, particularly for repositories with large numbers of worktrees or very large histories.\n\n## The core commands\n\n```bash\n# Create a new worktree for an existing branch, in a sibling directory\ngit worktree add ../myapp-hotfix hotfix/payment-bug\n\n# Create a new worktree AND a new branch at the same time\ngit worktree add -b feature/new-search ../myapp-search\n\n# List every worktree attached to this repository\ngit worktree list\n\n# Remove a worktree once you're done with it\ngit worktree remove ../myapp-hotfix\n\n# Clean up references to worktrees whose directories were deleted manually\ngit worktree prune\n```\n\nEach worktree checks out a different branch of the same repository — Git enforces that a branch can only be checked out in one worktree at a time, which prevents you from accidentally editing the same branch in two places and losing track of which one is current.\n\n## When a worktree beats the alternative\n\n| Situation | Without worktrees | With worktrees |\n| --- | --- | --- |\n| Urgent hotfix mid-feature | Stash feature work, switch branch, fix, switch back, unstash | New worktree, fix directly, remove worktree when done |\n| Reviewing a teammate's PR | Stash or commit work-in-progress just to check it out | Second worktree checks out the PR branch, original directory untouched |\n| Running a long test suite on main while coding a feature | Can't do both in one directory at once | One worktree runs tests on main, another has the feature checked out |\n| Comparing behavior across two branches | Two full clones, doubling disk space and remote setup | Two worktrees, one shared `.git`, far less disk overhead |\n\nA second full clone works too, but duplicates the entire object database on disk and needs its own remote configuration. A worktree shares history with the original clone, so it is lighter weight and stays in sync without a separate fetch.\n\n## Common mistakes\n\n**Expecting `node_modules` or build artifacts to carry over.** Worktrees share Git history, not the filesystem state outside of it — each one needs its own dependency install and will rebuild its own artifacts.\n\n**Trying to check out the same branch in two worktrees.** Git blocks this deliberately, since editing the same branch in two places at once is exactly the confusion worktrees are meant to prevent.\n\n**Letting worktrees accumulate without cleanup.** A worktree for every branch you've ever glanced at clutters `git worktree list` and can leave stale directories around long after the branch was merged or deleted.\n\n**Deleting a worktree's directory manually instead of using `git worktree remove`.** Git still tracks the worktree internally until you run `git worktree prune` or the proper remove command, which can cause confusing errors later.\n\n## FAQ\n\n**Do worktrees work with a bare repository?**\nYes — worktrees are commonly used with a bare clone as the central `.git` store, with every actual checkout living in its own worktree directory rather than one of them being the \"main\" working copy.\n\n**Can I use worktrees with Git submodules?**\nYes, though older Git versions had rough edges here; recent Git releases handle submodules inside worktrees reliably.\n\n**How is this different from just cloning the repo twice?**\nA second clone duplicates the full object database and needs its own remote tracking setup. A worktree shares the same underlying repository, so disk usage is far lower and both stay implicitly in sync.\n\n**Does each worktree need its own CI or build config?**\nNo, they use the same repository configuration — but local, uncommitted state like environment files, build caches, and installed dependencies is per-worktree and needs to be set up in each one separately.\n\n## Where to go next\n\nSee [feature branch vs trunk-based development for 2026](/blog/feature-branch-vs-trunk-based-2026) for the branching models worktrees make easier to work with day to day, and [feature flag rollout strategy for 2026](/blog/feature-flag-rollout-strategy-2026) for how trunk-based teams handle unfinished work without long-lived branches at all.","hue":304,"metaTitle":"Git Worktrees Explained for 2026","metaDescription":"Git worktrees explained for 2026: how to check out multiple branches at once without stashing, the core commands, and when they beat a second clone.","keywords":["git worktrees explained 2026","git worktree add","work on multiple branches at once","git worktree vs clone","git worktree tutorial","git worktree remove","context switch git branches","parallel git branches"],"tldr":["**A worktree is a second working directory linked to the same repo** — each one has its own checked-out branch, sharing one `.git` history underneath.","**No more stash-switch-unstash to context switch** — a hotfix, a PR review, and your current feature can each live in their own directory at the same time.","**`git worktree add` is the only command most people need** — creating, listing, and removing worktrees is simpler than the equivalent multi-clone setup.","**Each worktree needs its own dependency install and build artifacts** — they share history, not `node_modules`, build caches, or editor state.","**Skip:** running long-lived worktrees for every open branch — prune the ones you're done with, or `git worktree list` turns into its own kind of clutter."],"readTime":"4 min read","wordCount":868},"related":[{"slug":"ai-mcp-servers-explained-2026","title":"MCP servers explained in 2026: how Model Context Protocol works","excerpt":"Model Context Protocol turned one-off integrations into reusable servers any AI agent can call. Here is what MCP is, why it caught on, and when to use it.","category":"code","date":"May 4, 2026","author":"ByteLedger Team","readTime":"3 min read","hue":265},{"slug":"what-is-a-git-branch-2026","title":"What Is a Git Branch in 2026: a plain-language guide","excerpt":"A Git branch is a separate, movable line of work that lets you build or experiment without touching the main version of your project until you are ready to merge it back in.","category":"code","date":"June 22, 2026","author":"ByteLedger Team","readTime":"4 min read","hue":205},{"slug":"what-is-a-function-2026","title":"What is a function in programming in 2026? A clear guide","excerpt":"A function is a named, reusable block of code that takes inputs and returns a result. This guide explains how functions work, why they matter, and how to write a good one.","category":"code","date":"June 1, 2026","author":"ByteLedger Team","readTime":"4 min read","hue":142}],"sameCategory":[{"slug":"bazel-build-explained-2026","title":"Bazel Explained: What Hermetic Builds Actually Cost","excerpt":"Bazel delivers reproducible, precisely cached builds and demands that you describe everything. Here is what you get, what it costs, and who should say no.","category":"code","date":"August 19, 2026","author":"ByteLedger Team","readTime":"3 min read","hue":145},{"slug":"graphql-federation-2026","title":"GraphQL Federation: One Graph, Many Teams","excerpt":"Federation composes independently-owned subgraphs into a single API. Here is what it solves, the operational cost it adds, and when a simpler gateway is enough.","category":"code","date":"August 19, 2026","author":"ByteLedger Team","readTime":"3 min read","hue":300},{"slug":"hermetic-builds-explained-2026","title":"Hermetic Builds Explained: Same Inputs, Same Output","excerpt":"A hermetic build depends only on declared inputs. Here is what that property gives you, the common leaks that break it, and how to move toward it incrementally.","category":"code","date":"August 19, 2026","author":"ByteLedger Team","readTime":"3 min read","hue":130},{"slug":"monorepo-tooling-compared-2026","title":"Monorepo Tooling Compared: What You Actually Need","excerpt":"Monorepo tools solve task orchestration and caching, not repository layout. Here is what each tier provides and how to tell when you have outgrown the simple option.","category":"code","date":"August 19, 2026","author":"ByteLedger Team","readTime":"3 min read","hue":150}],"newer":{"slug":"gig-economy-taxes-explained-2026","title":"Gig Economy Taxes Explained: What You Owe in 2026","excerpt":"Gig economy taxes work differently than a paycheck job because nobody withholds anything for you. Here is how quarterly payments, self-employment tax, and deductions actually work in 2026.","category":"finance","date":"August 2, 2026","author":"ByteLedger Team","readTime":"3 min read","hue":287},"older":{"slug":"gpu-vs-tpu-for-inference-2026","title":"GPU vs TPU for Inference in 2026: Which to Pick","excerpt":"Serving a trained model is a different hardware problem than training one. Here is how GPUs, TPUs, and inference-specific chips compare on cost per token, latency, and software support.","category":"code","date":"August 2, 2026","author":"ByteLedger Team","readTime":"4 min read","hue":320}}