How to add multiple git worktrees to your repo example |Video upload date:  · Duration: PT3M12S  · Language: EN

Quick guide to add multiple git worktrees so different branches can be worked on at once without checkout conflicts.

Yes you can stop juggling checkouts like a circus act. With git worktree you can have multiple worktrees so different branches live in different folders and you never accidentally commit to the wrong branch again. This is pure developer hygiene and a tiny rebellion against endless context switching in the CLI.

Prepare your repository

Before you summon extra worktrees make sure your repository is clean and the branch you want exists or can be created. Use the familiar Git commands in the repo root to avoid surprises.

  • Confirm no uncommitted changes with git status
  • Create a branch up front if you need to with git branch feature-branch or create it from a commit or remote when you add the worktree

Create a new worktree

Adding a worktree is basically asking Git to give you a sibling folder with its own checkout. It links back to the same repository so you do not need another clone and you keep objects shared on disk.

git worktree add ../feature-branch feature-branch

That example creates a folder next to your current repo named ../feature-branch and checks out the branch called feature-branch there. If the branch does not exist and you created it earlier Git will use it. If you create it on the fly Git will place the branch in the new worktree.

What actually happens

  • A separate working directory appears in the sibling folder
  • Commits are stored in the same object store but the checkouts are independent
  • You can run editors tests and build tasks in each worktree without switching branches

Work inside the new worktree

Use the worktree just like a normal checkout. Run git status and git commit inside the worktree folder. Branch operations behave the same as in a clone. The main difference is that the main repo and the worktree are separate checkouts so you can keep one for an integration branch and another for a quick fix or experimental feature.

Clean up when a worktree is no longer needed

When you are done remove the linked checkout so Git does not keep stale metadata around. If the branch is no longer needed delete or merge it so it does not become an orphan.

git worktree remove ../feature-branch
# then optionally
git worktree prune

git worktree prune removes stale references to worktrees that are gone. Remember to delete or merge branches you no longer need to keep the repository tidy.

Developer workflow tips that actually help

  • Name each worktree folder to match the branch so shells editors and CI do not lie to you
  • Run long running tasks like tests or builds in their own worktree so they do not block quick edits
  • Prune stale worktrees periodically to avoid confusion and stale refs
  • Use multiple worktrees when you need parallelism not just for the novelty

Multiple worktrees speed up multitasking because you can keep context for each branch in its own folder. That reduces accidental commits on the wrong branch and makes parallel development with Git less painful. Go forth and branch responsibly.

I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!

This is a dedicated watch page for a single video.