Handling multiple branches in AI projects with git worktree
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:
- Run
git worktree list. - Copy the path.
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 removeInteractively prompts you to choose which worktree to delete.