Worktrees & Submodules
Two ways to have more than one thing checked out at once, for two completely different reasons.
Advanced
main) usually means
stashing whatever you were doing, switching, fixing, switching back, and unstashing. A
worktree is a second working directory, backed by the same
.git history, with a different branch checked out — no stashing required.
.gitmodules, no detached HEAD to manage) — anyone
who clones your repo gets everything immediately, with zero extra steps.
| Situation | Use |
|---|---|
| Fix a bug on another branch without losing your current work-in-progress | worktree |
| Build docs and code from the same repo side by side, in CI | worktree |
| Depend on another team's library, pinned to an exact version, updated deliberately | submodule |
| Vendor a small library's source directly, no extra clone step for contributors | subtree |