git worktree

Working on Two Branches at Once with git worktree

The limit fix should also reach users of 1.1.0 now, as 1.1.1, without the unreleased migration work on main. Instead of stashing again, Sam adds a worktree: a second working directory attached to the same repository, with its own branch, index and HEAD (Git 2.5 1,932 and later):

A release branch in its own worktree, and a patch release made thereShell
git worktree add -b release/1.1 ../booknest-1.1 v1.1.0
cd ../booknest-1.1
git cherry-pick -x main~1
npm version patch -m "Release %s"
git push -q -u origin release/1.1 --follow-tags
cd ../booknest
git worktree list
Output
Preparing worktree (new branch 'release/1.1')
HEAD is now at 5f14f72 Release 1.1.0
[release/1.1 ebadef9] Clamp ?limit= to 1-100 instead of failing with a 500
 Date: Fri Sep 25 13:15:00 2026 +0800
 2 files changed, 7 insertions(+), 1 deletion(-)
v1.1.1
/home/dev/v5-ch2/booknest     a62d631 [main]
/home/dev/v5-ch2/booknest-1.1 264b373 [release/1.1]

main~1 is the fix, one commit below the runner. The new directory shares the objects and refs of booknest; its .git is a one-line file pointing to .git/worktrees/booknest-1.1, so commits made there are visible from main at once. Git refuses to check out one branch in two worktrees, and untracked files such as node_modules/ are not shared, so run npm 2,036 ci in a new worktree before testing it. Worktrees suit long builds, reviewing a colleague's branch, and running two versions side by side.