Handling multiple branches in AI projects with git worktree

Published: (December 28, 2025 at 04:01 PM EST)
1 min read
Source: Dev.to

Source: Dev.to

Introduction

One of the most important features of Git for AI projects is git worktree. It allows you to check out different branches simultaneously in separate folders:

git worktree add

All worktrees share the same stash list, which is crucial when you need to run a long training job in one worktree, preprocess data in another, and fix a bug in a third—without conflicts or constant context switching.

Drawbacks of git worktree

The syntax of git worktree can be unintuitive, often requiring a quick lookup for common tasks.

Introducing gwt

To make git worktree easier to use, I created gwt, a simple helper that provides an intuitive interface.

Installation

Follow the instructions in the installation section of the repository.

Basic Usage

After installing, run:

gwt

This lists all available worktrees.

Before gwt

You would need to:

  1. Run git worktree list.
  2. Copy the path.
  3. cd ../../path/to/the-other-feature.

With gwt

Simply run gwt, select the branch, and you’re taken directly to the corresponding worktree.

Additional Commands

  • Create a new worktree

    gwt add <branch>

    This automatically creates a new worktree with the specified branch checked out.

  • Jump to an existing worktree

    gwt <branch>

    Supports autocomplete for branch names.

  • Remove a worktree

    gwt remove

    Interactively prompts you to choose which worktree to delete.

Back to Blog

Related posts

Read more »