Back to TIL

Git worktrees let you work on multiple branches simultaneously

git workflow

Instead of stashing changes or making WIP commits when you need to switch branches, you can use git worktrees to have multiple branches checked out at once!

# Create a new worktree for a feature branch
git worktree add ../feature-branch feature/new-thing

# Now you have two directories:
# ./my-project           (main branch)
# ./feature-branch       (feature/new-thing branch)

Each worktree is a fully functional checkout. You can:

  • Run different versions simultaneously
  • Keep a PR branch open while working on main
  • Review code without disrupting your current work

To list your worktrees:

git worktree list

To remove one when you’re done:

git worktree remove ../feature-branch

This has completely changed how I handle code reviews and hotfixes!