git: cd from worktree to main checkout

124 · Thiago Perrotta · Aug. 12, 2026, 3:40 p.m.
Summary
This post describes a shell function to enhance a Git workflow by allowing users to navigate back from a Git worktree to the main checkout directory efficiently. The author shares a problem they faced and provides a script solution that intelligently handles directory transitions, particularly when switching between a worktree and the main repository.