- Add SKILL.md (50 lines) managing branch/worktree lifecycle, rebase/squash integration, and evidence-first recovery - Add references/worktrees.md for worktree creation, locking, and clean removal - Add references/history-editing.md with conflict halt and abort guardrails - Add references/recovery.md for evidence-first reflog diagnosis and non-destructive branch restoration
1.7 KiB
1.7 KiB
Git Worktrees
Reference for git-workspace. Manage isolated working trees linked to the same underlying Git repository without cloning or stashing.
Use Cases
- Working on a quick fix or spike without stashing or switching branches in your main working tree.
- Running parallel test suites or builds in separate checkouts.
- Evaluating a PR branch while keeping current development intact.
Path Conventions
- Place worktrees outside the primary repository directory (for example,
../<repo>-<feature>or in a dedicated sibling directory), or under an ignored.worktrees/directory. - Never nest a worktree inside a tracked source directory.
Core Operations
1. Add Worktree
- For an existing branch:
git worktree add ../<repo>-<branch> <branch> - For a new branch off current base:
git worktree add -b feat/<name> ../<repo>-<feature> <base-ref>
2. Inspect Worktrees
- List all active worktree paths and their checked-out branches/SHAs:
git worktree list
3. Pinning / Locking
- Prevent accidental pruning when a worktree sits on removable or shared storage:
git worktree lock <path> --reason "active long-running test build" git worktree unlock <path>
4. Safe Removal
- Confirm working-tree status inside the worktree first:
git -C <path> status --short - If clean, remove cleanly:
git worktree remove <path> - If dirty, never run
git worktree remove --forcewithout explicit confirmation from the human owner describing what uncommitted edits will be discarded. - If a worktree directory was deleted manually, clean up administrative metadata:
git worktree prune