What is git worktree?
Why Interviewers Ask This
This tests whether you can apply Git & GitHub knowledge to real-world scenarios. Interviewers are looking for clarity of thought and evidence that you've encountered this in production code.
Answer
Git worktrees allow you to check out multiple branches simultaneously in separate directories, all sharing the same repository data. Each worktree has its own working directory and index. Without worktrees, switching branches means stashing or committing your current work. With worktrees, you can work on multiple branches concurrently. Commands: git worktree add ../hotfix hotfix-branch — check out hotfix-branch into a sibling directory ../hotfix; git worktree add -b new-feature ../feature — create and check out a new branch; git worktree list — list all worktrees; git worktree remove ../hotfix — remove a worktree; git worktree prune — clean up stale worktree metadata. Use cases: (1) Urgent hotfix while mid-feature — add a hotfix worktree, fix, build, test, push — without disturbing feature work; (2) Running tests on another branch while continuing to develop; (3) Comparing behavior between branches; (4) Long-running builds in a separate worktree. Constraints: you can't check out the same branch in two worktrees simultaneously. Each worktree uses minimal extra disk space (shared object store, just different working files).
Common Mistake
Rushing to answer is a common mistake. Take two seconds to structure your response: definition → example → trade-off. This structure makes complex Git & GitHub answers easy to follow.