DEV Community

Cover image for Boost Productivity: Using git-worktree with AI Coding Tools
Satoshi Ebisawa
Satoshi Ebisawa

Posted on

Boost Productivity: Using git-worktree with AI Coding Tools

Are you enjoying working with your favorite coding agents (GitHub Copilot, Cursor, Claude Code, OpenAI Codex, ...etc.) ?

Even these agents are getting faster and faster, you'll often find yourself waiting for them to finish their work.
While waiting for them, what do you usually do?

Editing your code while agents are working will confuse them. So, is waiting all you can do?

If you use git-worktree, you can do all of the following while your agents are working:

  • Fix another pull request to respond to your colleagues' code review
  • Fetch your colleagues' pull request and review locally
  • Tackle other issues
  • Work on documentation or tests in a separate branch
  • Handle urgent bug fixes
  • Let one agent generate code in one branch while you review another agent's output in a different branch

What's git-worktree?

git worktree lets you check out multiple branches into separate directories simultaneously. Unlike git checkout which switches your entire working directory, worktrees create additional working directories that all link back to your main repository.

The main benefits:

  • Work on multiple branches at once without stashing/committing
  • Each directory has its own independent state
  • All worktrees share the same Git history (efficient storage)
  • Perfect for parallel development workflows

How to use

# Create a worktree for an existing branch
git worktree add ../feature-login feature/login

# Create a new branch and worktree in one command
git worktree add -b fix/api-error ../api-fix main

# List all your worktrees
git worktree list

# Remove a worktree when done
git worktree remove ../feature-login
Enter fullscreen mode Exit fullscreen mode

Remember that .env files and other files in .gitignore won't be copied to new worktrees. Copy these manually when needed.

Conclusion

By combining git worktree with coding agents, you unlock a truly parallel development workflow. While agents are busy generating code in one directory, you can be productive in another. This approach eliminates idle waiting time and maximizes your productivity.

Top comments (0)