Git Worktrees

Git worktrees allow you to check out multiple branches simultaneously without re-cloning the repository multiple times. This is an alternative to using “stash” to save uncommited changes and switching branches.

For example, if we are currently on branch feature/ticket-number-xxxx and want to go work on bugfix/ticket-yyyy, we can run the command

git worktree add ../proj-ticket-yyyy bugfix/ticket-yyyy

The command is to be run from the root directory of your repo, but the worktree itself will be created in the parent directory (or elsewhere). There is no .git folder in the new folder that gets created, but instead it has a .git file. It is recommended to do it this way to avoid confusion from nesting folders in the same repo.

You can run git commands such as commit, push, pull, rebase etc. in the separate worktree folder even while another branch is checked out in your original folder.

Once you are done with the branch, you can run git worktree remove . to remove the folder with the worktree.

A worktree is also useful when doing code reviews if you want to check out an existing branch without moving away from whatever branch you were working on. This is especially useful on projects with long compile times when switching between branches.

Worktrees are also very useful when working with agentic coding tools like Claude Code. You can have multiple parallel instances of the AI working on different branches of the code simultaneously 2.

References

[1] Git Worktrees - An Alternative to Git Stash [2] How I am using Coding Agents in September 2025

Backlinks

  • Software Development