Andrew's Digital Garden

Git worktree

git worktree is a Git feature that allows you to check out multiple branches at once in different directories, without cloning the repository again

Worktrees are kind of like an alternative to stash. This lets you truly multitask, having different branches in different locations.

Here are a few use cases for git worktree

  • checkout changes while compiling or running tests
  • comparing two versions simultaneously
  • efficiently switch between branches without having to recompile, IDE reindex the code, reopen files etc.
  • switch between branches without having to stash, or make WIP commits

The command is git worktree add <location> <name> You can place the worktree wherever you want, but it has to be outside of the current directory so it's not tracked, e.g. git worktree add .worktrees/<repo>/bug/fix-bar bug/fix-bar or git worktree add ../my-repo-v5 master-v5

Your worktrees are denoted with a plus (+) when using a command like git branch.

There's of course a git worktree list and a git worktree remove

I personally keep everything in code/worktrees/<worktree>, and name it as <repo>-<branch> more or less. This is done through gwt, gwta aliases.

With the rise of [[20250811123613-agentic-ai]], worktrees can be even more useful, having agents act in different directories simultaneously.

[[ai]] [[git]]

Git worktree