Worktrees

Worktrees

Worktrees are git’s built-in feature for having multiple working directories from a single repository. Bearing uses them to isolate work.

How They Work

A worktree is a separate working directory with its own checked-out branch, but sharing the same git history:

myapp/                    # Base folder (main branch)
β”œβ”€β”€ .git/                 # Main git directory
β”œβ”€β”€ src/
└── package.json

myapp-feature-auth/       # Worktree (feature-auth branch)
β”œβ”€β”€ .git                  # File linking to main .git
β”œβ”€β”€ src/                  # Separate working copy
└── package.json

Benefits

Lifecycle

# Create worktree for a task
bearing worktree new myapp feature-auth

# Work in it
cd myapp-feature-auth
git add . && git commit -m "Add auth"
git push -u origin feature-auth

# Clean up after merge
bearing worktree cleanup myapp feature-auth

Git Commands (Under the Hood)

Bearing wraps these git commands:

# Creating a worktree
git -C myapp worktree add ../myapp-feature-auth -b feature-auth

# Listing worktrees
git -C myapp worktree list

# Removing a worktree
git -C myapp worktree remove ../myapp-feature-auth
git -C myapp worktree prune

You can use git directly if neededβ€”Bearing won’t break.