Git working directory and worktree
Definition
A Git working directory contains checked-out files; additional worktrees enable separate working states of the same repository in multiple directories.
The working directory contains the files you edit in a Git project. A worktree includes this working state and associated Git management information. With additional linked worktrees, different working states of the same repository can be edited in separate directories while sharing common repository data.
Simply explained
You can set up multiple workspaces for the same project without constantly stashing unfinished changes or recloning the entire content.
Why it matters in practice
Separate worktrees facilitate parallel tasks, such as bug fixing and feature development, while keeping the assignment to branches and working states traceable.
Example from business
Hypothetical example: A developer creates an additional worktree alongside her ongoing feature work to fix a bug on another branch.
Limits and pitfalls
- Worktrees share repository data and are not fully independent copies. Uncommitted files and local configuration must be considered per working directory.
Origin & history
Git distinguishes stored history from checked-out files. Linked worktrees extend this model by multiple working directories for one repository.
Use in mid-sized companies
- Development teams can spatially separate tasks and test changes specifically without interrupting ongoing work by frequently switching working states.
Frequently asked questions
Is a clean worktree a specific branch?
No. Clean describes the absence of local changes compared to the considered state; branch denotes a development line.
Sources
- git-worktree. · Git (o. J.): git-worktree.
Editorially reviewed on: