Git Worktrees in 2026: How to Work on Multiple Branches Without Switching

Working with multiple Git branches can become frustrating.

Imagine you’re developing a new feature when your team reports a critical production bug. You need to fix it immediately. However, your current branch contains unfinished changes.

Normally, you might stash your work, switch branches, fix the issue, and return to your original task.

Fortunately, Git worktrees offer a better approach.

Git worktrees allow developers to work on multiple branches in separate directories while sharing the same Git repository.

As a result, you can develop features, fix bugs, and review code without constantly switching branches.

In this guide, you’ll learn how to use Git worktrees in 2026, explore practical commands, and discover how they can improve your development workflow.

What Are Git Worktrees?

A Git worktree is a working directory connected to an existing Git repository.

Normally, a Git repository has one working directory where you edit files.

However, Git worktrees allow you to create additional working directories.

Each worktree can have its own checked-out branch and files.

Meanwhile, the worktrees share the repository’s underlying Git object database and much of its metadata.

For example, imagine your project has three branches:

  • main
  • feature/dashboard
  • hotfix/login

Instead of switching between them, you can work on each branch in a separate folder.

Therefore, your unfinished changes remain in their original workspace.

How Do Git Worktrees Work?

Git worktrees connect multiple working directories to the same repository.

For example, your folder structure might look like this:

projects/
├── my-app/
├── my-app-dashboard/
└── my-app-hotfix/

Each folder represents a separate working directory.

However, all three belong to the same Git repository.

This means you can open each directory in a different editor window.

In addition, you can run different development servers for each branch.

As a result, switching between tasks becomes easier.

Git Worktree vs. Git Branch

Git branches and worktrees are related, but they aren’t the same thing.

A branch represents a line of development.

Meanwhile, a worktree provides a directory where you can check out and edit files.

Here’s a comparison:

FeatureGit BranchGit Worktree
PurposeTrack a line of developmentProvide a separate working directory
Separate filesNot by itselfYes
Branch switchingUsually required in one directoryNot required between worktrees
Uncommitted changesStay in the current working directoryRemain isolated in each worktree
Repository objectsSharedShared
Multiple editor windowsPossibleSeparate branch-specific workspaces

Therefore, Git worktrees don’t replace branches.

Instead, they make working with multiple branches more convenient.

1. How to Create a Git Worktree

Creating a worktree is straightforward.

First, open your existing Git repository.

For example:

cd my-app

Next, create a worktree for a new feature branch:

git worktree add -b feature/dashboard ../my-app-dashboard

This command performs two actions.

First, it creates a new branch called feature/dashboard.

Then, it creates a separate directory called my-app-dashboard.

You can now open that folder in your code editor.

cd ../my-app-dashboard

Any changes you make in this directory belong to its working tree.

Meanwhile, your original working directory remains unchanged.

2. How to Create a Worktree From an Existing Branch

Sometimes the branch already exists.

For example, imagine your repository contains a branch called hotfix/login.

You can create a worktree using:

git worktree add ../my-app-hotfix hotfix/login

Git creates the new working directory and checks out the specified branch.

However, Git normally prevents the same branch from being checked out in multiple worktrees simultaneously.

Therefore, make sure the branch isn’t already checked out elsewhere.

This restriction helps prevent conflicting operations on the same branch.

3. How to List Git Worktrees

As your project grows, you may create several worktrees.

Fortunately, Git provides a simple command to view them.

git worktree list

Example output:

/projects/my-app            abc1234 [main]
/projects/my-app-dashboard  def5678 [feature/dashboard]
/projects/my-app-hotfix     ghi9012 [hotfix/login]

This output shows each worktree’s location, current commit, and checked-out branch.

As a result, you can quickly identify your active workspaces.

For more detailed information, use:

git worktree list --porcelain

This format is especially useful for scripts and automation.

4. How to Remove a Git Worktree

Once you finish a task, you may no longer need its worktree.

For example, imagine you’ve merged your dashboard feature.

You can remove its working directory with:

git worktree remove ../my-app-dashboard

This removes the worktree while preserving the branch.

However, Git normally refuses to remove a worktree containing uncommitted changes.

Therefore, commit, discard, or otherwise preserve important changes first.

If you also want to delete the merged branch, use:

git branch -d feature/dashboard

Be careful when deleting branches.

Always confirm that important changes have been merged or preserved.

5. Git Worktrees vs. Git Stash

Git stash temporarily saves uncommitted changes.

For example, developers often use:

git stash

Then, they switch branches:

git switch main

Later, they restore their changes:

git stash pop

This workflow works well for occasional interruptions.

However, it can become inconvenient when switching tasks frequently.

Git worktrees provide another option.

Instead of hiding unfinished changes, you leave them in a separate working directory.

When to Use Git Stash

Git stash is useful when you need to temporarily set aside changes in one workspace.

When to Use Git Worktrees

Git worktrees are useful when you want multiple branches available at the same time.

Therefore, the best choice depends on how you prefer to organize your development tasks.

6. Git Worktrees for Hotfixes

Hotfixes are one of the most practical Git worktree use cases.

Imagine you’re building a new dashboard.

Suddenly, a customer reports that the login page isn’t working.

Your dashboard feature isn’t finished.

However, the login problem needs immediate attention.

Instead of interrupting your current workspace, create a new worktree:

git worktree add -b hotfix/login ../my-app-hotfix main

Next, open the new directory:

cd ../my-app-hotfix

You can now fix the login issue independently.

After testing the solution, commit your changes:

git add .
git commit -m "Fix login issue"

Then, push the branch:

git push -u origin hotfix/login

Once the hotfix is reviewed and merged, you can remove the extra worktree.

Meanwhile, your dashboard changes remain untouched.

As a result, you can return to your original task without restoring a stash.

7. Git Worktrees for Code Reviews

Code reviews often require developers to inspect another branch.

However, switching away from unfinished work can be inconvenient.

Git worktrees solve this problem.

For example, imagine you need to review a branch called feature/payments.

First, fetch the latest remote changes:

git fetch origin

Then, create a separate worktree:

git worktree add --detach ../my-app-review origin/feature/payments

This creates a detached-HEAD worktree at the remote branch’s current commit.

You can now inspect and test the code without changing your main workspace.

However, if you plan to make commits, create a local branch instead.

Therefore, detached worktrees are particularly useful for temporary reviews and testing.

8. Git Worktrees With VS Code

Git worktrees work well with Visual Studio Code.

For example, you can open your main project:

code my-app

Then, open a feature worktree in another window:

code my-app-dashboard

Each window has its own files and Git status.

In addition, you can run separate terminals and development servers.

However, remember that worktrees share Git repository data.

Changes to shared branches and references may affect what other worktrees see.

Still, working files and uncommitted edits remain separate.

9. Git Worktrees With Docker

Git worktrees can also help developers test different application versions.

For example, you might run a stable version in one directory and an experimental feature in another.

Each worktree can contain its own Docker Compose configuration.

However, running both environments simultaneously may create conflicts.

Common problems include:

  • Duplicate container names
  • Conflicting host ports
  • Shared volume names
  • Identical Compose project names
  • Overlapping local services

Therefore, configure separate ports and project names when needed.

For example:

docker compose -p app-feature up -d

This starts a Compose project using the specified project name.

If you’re exploring container development, our guide to Docker vs. Podman in 2026 explains how these tools compare.

10. Git Worktrees for AI Coding Agents

AI coding agents are another interesting use case for Git worktrees.

For example, imagine assigning separate development tasks to two coding agents.

One agent works on authentication.

Meanwhile, another works on a dashboard feature.

If both agents modify the same working directory, their changes may conflict.

However, separate Git worktrees provide isolated working files for each task.

For example:

git worktree add -b ai/auth ../ai-auth main

Then:

git worktree add -b ai/dashboard ../ai-dashboard main

Each agent can work in its own directory.

However, separate worktrees don’t eliminate merge conflicts.

If both agents modify the same code, developers still need to review and integrate their changes carefully.

In addition, AI-generated code should be tested before merging.

For more information, explore our article about AI Coding Agents in 2026 and how autonomous tools are changing development workflows.

11. Git Worktrees for Testing Different Versions

Sometimes developers need to compare two versions of an application.

For example, you might want to test a new API implementation against the current production branch.

Instead of repeatedly switching branches, create separate worktrees.

One directory can run the stable version.

Meanwhile, another runs the experimental version.

This approach makes side-by-side testing easier.

However, remember that each worktree may need its own dependencies and build files.

For example, Node.js projects may require separate node_modules directories.

Therefore, worktrees can consume additional disk space even though they share Git objects.

12. Git Worktree Best Practices

Git worktrees are powerful. However, good organization is important.

Use Clear Directory Names

Choose names that describe the task.

For example:

my-app/
my-app-login-fix/
my-app-dashboard/
my-app-review/

This makes your workspace easier to navigate.

Remove Unused Worktrees

Old worktrees can clutter your development environment.

Therefore, periodically review them using:

git worktree list

Then, remove directories you no longer need.

Keep Dependencies Organized

Each worktree has separate working files.

As a result, dependencies and build artifacts may need to be installed separately.

Avoid Sharing the Same Branch

Git normally prevents a branch from being checked out in multiple worktrees.

Therefore, create separate branches for independent tasks.

Review Changes Before Merging

Worktrees isolate working directories, not the logic of your application.

Consequently, merge conflicts and integration problems can still happen.

Common Git Worktree Mistakes

Developers sometimes misunderstand how worktrees manage files and branches.

Here are several mistakes to avoid.

Deleting Worktree Folders Manually

Removing a folder directly may leave administrative worktree information behind.

Instead, use:

git worktree remove ../my-app-review

If a worktree was already deleted manually, you can clean stale metadata with:

git worktree prune

Assuming Worktrees Are Separate Repositories

Worktrees share the same repository data.

Therefore, they aren’t completely independent clones.

Forgetting About Environment Files

Different worktrees may require different local settings.

For example, development servers may need separate ports.

Therefore, configure environment files carefully.

Running Too Many Worktrees

Creating worktrees is easy.

However, maintaining too many active environments can become confusing.

Instead, keep only the workspaces you actually need.

Frequently Asked Questions About Git Worktrees

What is a Git worktree?

A Git worktree is an additional working directory connected to an existing Git repository. It allows developers to work on different branches simultaneously.

Are Git worktrees better than branches?

Git worktrees don’t replace branches. Instead, they provide separate directories for working with branches.

Do Git worktrees use more disk space?

Yes. Each worktree contains its own working files and potentially separate dependencies. However, Git objects are shared, which can save space compared with full clones.

Can I use Git worktrees with VS Code?

Yes. You can open different worktrees in separate VS Code windows.

Can two worktrees use the same branch?

Git normally prevents the same branch from being checked out in multiple worktrees simultaneously.

Are Git worktrees useful for AI coding agents?

Yes. Separate worktrees can provide isolated working directories for different agent tasks. However, developers still need to review changes and resolve integration conflicts.

How do I delete a Git worktree?

Use git worktree remove followed by the worktree path. Make sure important uncommitted changes are preserved first.

Final Thoughts

Git worktrees in 2026 offer a practical way to manage multiple development tasks.

Instead of constantly switching branches, developers can keep separate working directories for features, hotfixes, and code reviews.

As a result, unfinished changes remain in their original workspace.

In addition, worktrees can support parallel development, container testing, and AI-assisted coding workflows.

However, they don’t replace Git branches or eliminate merge conflicts.

Instead, they provide a more flexible way to organize your existing repository.

If you frequently switch between tasks, Git worktrees are worth exploring.

A better Git workflow isn’t about using more commands. It’s about reducing interruptions and keeping development organized.