DEV Community

livecodelife
livecodelife

Posted on

How I Supercharged My Workflow with Git Worktrees

While venting to ChatGPT about how painful it was to switch branches every time I got feedback on a PR, I discovered Git worktrees. I’d open a PR for a new feature, wait for reviews, then jump onto another task—only to have to git checkout back later when reviewers chimed in. It felt like constantly tearing down and rebuilding my mental context. I mentioned this to ChatGPT, and it suggested trying Git worktrees to keep multiple branches checked out at once. After some research, and talking more with ChatGPT about conventions and pitfalls, I started using this feature at work. Within minutes I had two worktrees live: one for my open PR, and another for my new feature. Now I could let Cursor build out a plan in one window while coding in the other. When comments rolled in on my PR, I simply switched windows without ever dropping my existing work.

After sharing this trick with teammates, I realized most engineers weren’t aware this was even a Git feature. A Reddit post I stumbled upon confirmed that Anthropic’s Claude Code users have been leveraging worktrees to run parallel AI coding sessions. The surprise I was met eith when I mentioned that this was a native git feature it was proof that this capability is still under-hyped.


Where the Pros Are Already Using It

  • Anthropic (Claude Code) Anthropic’s internal docs walk through creating separate worktrees for different Claude sessions:
  git worktree add ../feature-auth feature-auth
  cd ../feature-auth && claude
Enter fullscreen mode Exit fullscreen mode

You can spin up parallel Claude Code windows—each isolated to its own branch—so AI tasks don’t step on each other’s toes.

  • Atlassian Sourcetree
    Sourcetree added Git worktree support back in 2015, highlighting how useful it is for large projects with multiple branches. Today, both GUI and CLI users tap into worktrees without ever thinking about cloning a repo twice.

  • VS Code & JetBrains IDEs
    Extensions like “Git Worktrees” for VS Code or built-in support in IntelliJ let you create, switch, and manage worktrees right from your editor—making them just as accessible as standard branch checkouts.

  • Open-Source Projects & Mono-Repos
    Big mono-repo teams often need isolated environments for different features or releases. Worktrees let you keep each in its own directory, so you avoid full clones and minimize duplicate storage.


My Top Tips & Tricks

  • Use Descriptive Folder Names
   git worktree add ../feature-ui-redesign ui-redesign
Enter fullscreen mode Exit fullscreen mode

Name each worktree folder after the branch or task so your terminal prompt and editor window both remind you what you’re working on.

  • Initialize Every Worktree
    Each new directory is like a fresh clone. Remember to run your setup steps—npm install, bundle install, or your language’s build commands—so your tools and dependencies are ready.

  • One IDE Window & Terminal per Worktree
    Keep one editor window and one terminal tab open in each worktree. This makes it crystal clear which branch you’re on and prevents cross-branch file watcher or cache issues.

  • Avoid Checking Out the Same Branch Twice
    Git will refuse to attach the same branch to multiple worktrees. If you need a duplicate, create a temporary branch (git checkout -b feature-copy) or use a detached HEAD (git worktree add -d <path).

  • Clean Up When You’re Done

   git worktree remove ../feature-ui-redesign
   git worktree prune
Enter fullscreen mode Exit fullscreen mode

Remove worktrees when features ship or batteries die. git worktree list shows all your active worktrees, and prune cleans up any that got deleted manually.

  • Mind Your Background Processes
    If you have build watchers, dev servers, or AI sessions running, keep them confined to their worktree. Stop them before hopping to another to avoid port collisions or CPU overload.

  • Repair & Move Worktrees Safely
    If you accidentally move a worktree folder, run git worktree repair <new-path> in the main repo. Use git worktree move <old-path> <new-path> if you want to rename or relocate cleanly without breaking links.


Wrapping Up (and What to Watch Out For)

Git worktrees turned my PR-feedback treadmill into a smooth flow of parallel tasks. With Cursor (or any AI assistant) running in one worktree and my coding in another, I shaved hours off context switches every day. Plus, when bugs surface post-deploy, I’ve still got that worktree handy with all the latest changes, ready for a quick fix.

Caution: It’s tempting to spin up a dozen worktrees and juggle every task at once. That can splinter your focus and lead to burnout. Start with a couple—maybe one for active features and one for hotfixes—and scale consciously. A clean, focused workflow beats a cluttered one every time.

Give it a try on your next multi-branch stint. Clone once, work everywhere. 

Top comments (0)