Define scope before changing context
A fictional APS team receives a daily-close incident while preparing a feature. The fix must start from the approved release; the current index contains unreviewed work. Before running commands, identify the release base, staged work, remaining edits, and untracked files relevant to investigation. The operational question is how to prepare a small change without losing or accidentally including pending work. Write the decision and the evidence you will collect. A branch name or hotfix message does not establish correct content selection.
Compare two worktrees in the lab
In the local lab, app.txt starts with base. The main worktree stages draft and records its staged diff. Then worktree add -b urgent creates another worktree from HEAD. In the new directory, app.txt still contains base and its index has no changes. After a fix commit in that worktree, the main staged diff remains unchanged. The runner confirms these observations in temporary repositories. The exercise uses Git 2.50.1 Apple Git-155; current documentation inspected is from the 2.56 line. No application was executed and no real release was validated.
Recognize what remains shared
Separate indexes and HEADs do not create two independent repositories. The urgent branch became visible from the main worktree and both resolved to the same common repository directory. This matters when a team changes references or configuration: repository configuration is shared by default. Do not use another worktree as an authorization boundary or independent backup. In the change meeting, explain that you separated work being edited but still need coordination over branches and publication. For specific configuration, review worktreeConfig and compatibility of the versions in use.
Choose what to retain with stash
In another lab, app.txt has a tracked edit, notes.txt is untracked, and cache.tmp is ignored. Stash push -u saves the first two; cache.tmp remains. Stash apply restores work and retains the entry for review. Ask the learner to compare status, diff, and stash list before considering the task complete. If restoring staged selection matters, --index attempts that too but may fail with conflicts. A conflicted pop does not automatically delete the entry. Avoid repeating the command reflexively: first interpret state and change intent.
Close the fix with evidence
Deliver a note identifying the base commit, fix commit, changed files, and tests performed in the release context. Before removing the worktree, check for diagnostics or unsaved edits. An empty diff on tracked files does not exclude untracked files. Runner content/labs/git-recovery/run.py reproduces local experiments without remotes, personal configuration, hooks, or signing. Summary: separate commit selection, confirm stash scope, and preserve evidence before cleanup. Connect this lesson with the index, remotes, code review, and incident management.
The main staged diff stayed identical after creating and changing the urgent worktree.
Common pitfalls
Worktree as independent clone; -u as including ignored files; conflicted pop as a lost entry.
Related topics: Working tree, index, and commit · Branches, merge, and rebase · Reverse changes and preserve work
Separate contexts and explicitly verify the work retained by each operation.
Reference: Git: worktree · Git 2.56; workflow concepts compatible with modern Git 2.x