Skip to main content
  1. Today I Learned (TIL)/

git worktree, the flow AI made me learn

·214 words·2 mins·

Today I finally learned git worktree, a command that’s been in git for years and that I’d somehow never reached for until AI tooling started using it for me.

The idea: one repository, multiple working directories, each checked out to a different branch at the same time. git worktree add ../myproject-hotfix hotfix gives you a second folder on disk, sharing the same .git history, where you can work on hotfix without touching your main checkout. No second clone, no stash dance, no re-downloading the whole history.

In ordinary solo work I never needed it. You finish a branch, switch, move on, and git switch is enough. What changed is parallel work: agents that each want an isolated checkout so they can build and edit without colliding, and me wanting to review one branch while another is mid-change. Worktrees are the clean primitive for that, far cheaper than cloning.

The catch I hit: you can’t check out the same branch in two worktrees at once, which is git protecting you from yourself. And worktrees linger if you forget them, so git worktree list to see them and git worktree remove to clean up. It’s one of those tools that felt unnecessary right up until the workflow demanded it, and now I reach for it weekly.

Chandler Thompson
Author
Chandler Thompson
I lead engineering teams and coach the people who run them. This is where I write down what actually worked.

Related