Daniel Lyons' Notes

How Git Worktrees Changed My AI Agent Workflow

Notes

00:00 Introduction to Git Work Trees

  • What are git work trees?
    • A feature for creating multiple working directories of the same repository
    • Particularly useful when incorporating AI agents into development workflow
  • Key benefit: Work on multiple branches simultaneously without context switching
    • AI agents can work on a copy while you continue on your current task
    • Eliminates need to manually copy repositories

00:46 Use Cases for Git Work Trees

  • 01:02 Fixing failed CI without interrupting current work
    • Normally requires stashing changes or temporary commits
    • Git work trees provide a cleaner solution
  • 01:46 Manual repository copying (alternative without work trees)
    • Previous workaround before discovering native git feature

01:50 How Git Work Trees Work

  • 01:56 Creating a work tree
    • Command: git worktree add [path] [branch-name]
    • Example: git worktree add nx/feature-a feature-a
    • Automatically initializes all files and sets up the branch
  • 02:51 Opening work trees in your editor
    • Navigate to the created folder and open with your preferred IDE (Cursor, VS Code, etc.)
    • Fresh repository copy ready for development
  • 03:18 Managing multiple work trees
    • Command: git worktree list to see all connected work trees
    • Git automatically tracks all work trees in the repository
  • 03:31 Merging work tree changes
    • Can merge work tree branches back like normal branches: git merge feature-a
    • Typical workflow: commit on work tree branch → submit PR → merge to main → remove work tree
  • 04:08 Removing work trees
    • Command: git worktree remove [path]
    • Example: git worktree remove nx/feature-a
    • Cleans up and removes from work trees list

04:31 The worktree CLI Tool by John Linquist

  • 04:41 Simplifying work tree management
    • Created by John Linquist (co-founder of Acad)
    • Reduces ceremony around git work tree setup
  • 05:03 Installation
    • Install globally via npm: npm install -g @johnlindquist/worktree@latest
    • Provides wt shortcut command
  • 05:27 Available commands
    • wt list: List all work trees
    • wt new [feature-name]: Create new work tree and auto-open in editor
    • wt remove: Remove work trees
    • wt merge: Merge work trees
    • wt purge: Clean up unused work trees
    • wt extract: Extract existing branch into new work tree
  • 06:01 Features and automation
    • One-line creation with automatic editor opening
    • Built-in naming conventions: repo-branch-name format
    • Can automatically install npm/pnpm modules
    • Customizable configurations
  • 06:51 Checking out PRs directly
    • Command: wt pr [PR-number] to check out PR in its own work tree
    • Works similarly to GitHub CLI but in isolated work tree
    • Allows code review and testing without disrupting current workflow

07:36 Bonus: NX Cloud Self-Healing CI

  • 07:43 Automatic CI fixes
    • AI automatically fixes CI failures in your PRs
    • No need to manually check out and fix failed builds
  • Integrated workflow: AI proposes fix → you approve → automatically pushed and re-run
  • Free hobby plan available
How Git Worktrees Changed My AI Agent Workflow
Interactive graph
On this page
Notes
00:00 Introduction to Git Work Trees
00:46 Use Cases for Git Work Trees
01:50 How Git Work Trees Work
04:31 The worktree CLI Tool by John Linquist
07:36 Bonus: NX Cloud Self-Healing CI