Skip to content
November 16, 2026

How Do You Work on Multiple Git Branches at the Same Time Without Constant Switching or Git Stash?

You are halfway through a feature.

Your files are modified, the code is not ready to commit, and suddenly an urgent production issue comes in.

The usual workflow is:

git stash
git switch main
git pull
git switch -c hotfix/production-issue

Then after the fix:

git switch feature/my-feature
git stash pop

It works, but repeated branch switching and stashing quickly becomes painful.

A cleaner option is Git worktrees.

What is a Git worktree?

A worktree lets you check out multiple branches from the same Git repository into separate folders.

Instead of:

one folder
    ↓
switch branches repeatedly

you can have:

springboot-example-svc/
    → feature/customer-search
springboot-example-svc-hotfix/ 
    → hotfix/invalid-customer-id

Each branch gets its own working directory.

Your uncommitted feature work stays exactly where it is.

No stash required.

Example

Assume you are working on:

cd ~/projects/springboot-example-svc
git switch -c feature/customer-search

You have unfinished changes in:

CustomerController.java
CustomerService.java

Then an urgent production bug arrives.

Instead of switching branches, create another worktree:

git fetch origin
git worktree add \
  -b hotfix/invalid-customer-id \
  ../springboot-example-svc-hotfix \
  origin/main

Now you have:

springboot-example-svc/
    feature/customer-search
    unfinished work stays here
springboot-example-svc-hotfix/
    hotfix/invalid-customer-id
    clean workspace for the fix

Open the second folder in another terminal or IDE window:

cd ~/projects/springboot-example-svc-hotfix

Fix the bug, test it, commit it, and push it:

./mvnw test
git add .
git commit -m "Fix invalid customer ID handling"
git push -u origin hotfix/invalid-customer-id

Raise the PR and merge it into main.

Meanwhile, your feature workspace was never touched.

Go back to it:

cd ~/projects/springboot-example-svc

You are still on:

feature/customer-search

with all your unfinished work intact.

Once the hotfix is merged, bring the latest main into your feature:

git fetch origin
git rebase origin/main

or:

git merge origin/main

When you are done with the temporary workspace:

git worktree remove ../springboot-example-svc-hotfix

The Mental Model

The easiest way to think about worktrees is:

Instead of switching the same workspace between branches, give each branch its own workspace.

That means:

One Git repository
        │
        ├── Feature workspace
        │     feature/customer-search
        │
        └── Hotfix workspace
              hotfix/invalid-customer-id

Both can be open at the same time.

This becomes even more useful when using coding agents: one workspace can be used by you, while another agent works independently on a hotfix or another feature.

Key Commands

git worktree list
git worktree add -b new-branch ../new-folder origin/main
git worktree remove ../new-folder

Final Thought

git stash and git switch are still useful.

But when you need to work on two branches in parallel, Git worktrees are often a much cleaner option.

As AI coding agents become part of everyday development, parallel work becomes much more common. Git worktrees give each developer or agent an isolated workspace, so one can work on a feature while another handles a hotfix without stepping on the same files.

One repository. Multiple branches. Separate workspaces. Less context switching.

Tags:

Leave a Reply