feat(git-workspace): add workspace, worktree, integration, and recovery skill

- 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
This commit is contained in:
kiskaadee committed 2026-10-31 09:31:31 -05:00
1 parent a1cf7d3aaf
commit 501ec5cd3c
4 files changed
+181 -1

No files matched your search

+50
View File
@@ -0,0 +1,50 @@
---
name: git-workspace
description: >-
Manage Git branches, worktrees, history integration (rebase, squash, cherry-pick),
conflict stops, and evidence-first reflog recovery. Use when creating branches or
worktrees, synchronizing branches, editing history, or recovering lost commits.
Not for slicing checkpoint commits: use git-commit.
---
# Git Workspace
## Use when
- Creating dedicated feature branches or isolated worktrees before making edits.
- Integrating branches (rebase, squash, merge, cherry-pick) or resolving conflicts.
- Recovering lost commits, dangling refs, or broken working-tree state via reflog.
- Not for slicing uncommitted diffs into checkpoint commits: use `git-commit`.
## Steps
1. **Inspect state.** Resolve target repository root (`git rev-parse --show-toplevel`), active branch,
upstream tracking, clean vs. dirty status (`git status --short`), and reflog head. All commands execute
strictly from the target repository root.
2. **Branch and worktree management.** Enforce the branch-before-edits invariant. Create dedicated feature
branches (`git switch -c <name>`). When working across parallel tasks or spikes without disturbing current
working-tree state, create an isolated worktree following [references/worktrees.md](references/worktrees.md).
Never remove a worktree containing uncommitted or unmerged work without explicit confirmation.
3. **Integration and history editing.** Rebase local unshared branches onto upstream base; collapse fixup
checkpoints via squash; cherry-pick with dependency checks. On any merge or rebase conflict: stop immediately,
report conflicting files and hunks in prose, never guess resolution, and offer clean abort (`git rebase --abort`).
Follow [references/history-editing.md](references/history-editing.md).
4. **Evidence-first recovery.** When a commit, branch, or working-tree state appears lost or corrupted, inspect
evidence first (`git reflog`, `git fsck`, `git branch -v`) to identify exact candidate SHAs and timestamps
before proposing any fix. Never run destructive resets (`git reset --hard`) as a speculative remedy. Restore
discovered state into a dedicated recovery branch. Follow [references/recovery.md](references/recovery.md).
5. **Verify post-operation state.** Confirm target ref, commit log (`git log -n 3 --oneline`), and clean working
tree before concluding.
## Your call
- **Branch and worktree naming and target paths**: choose names and locations for new branches or worktrees.
- **Integration strategy**: choose rebase vs. merge when an architectural choice exists.
- **Conflict resolution**: adjudicate conflicting hunks when git stops during integration.
- **Consequential and destructive actions**: require explicit confirmation with impact described first per
`profile/AGENTS.md` before running destructive commands (`git reset --hard`, force-push, worktree removal).
## Done when
- Target branch or worktree is created, integrated, or safely cleaned up; or lost ref is restored to a named
branch with observable verification evidence.
## Hands off to
- `git-commit`: when code changes are ready to be sliced, reviewed, and committed.
- `code-review`: when a branch or PR diff is ready for multi-axis static review before integration.
@@ -9,16 +9,18 @@ Rules for rewriting or combining history. Read before any of these operations.
## Rebase
- Fine on local, unshared branches, to keep history linear and tidy before integrating.
- Never rebase or force-push a branch others may have pulled without my explicit OK.
- On conflicts: stop immediately. Inspect `git status --short` and conflicting hunks. Never guess resolution. Offer `git rebase --abort` to return cleanly to prior state if resolution is uncertain.
## Cherry-pick
1. Inspect the source commit and what it depends on.
2. Confirm the target working tree is clean.
3. Cherry-pick, inspect the resulting diff, run validation.
4. On conflicts or hidden dependencies: stop and report.
4. On conflicts or hidden dependencies: stop and report. Offer `git cherry-pick --abort`.
## Merge
- Follow the repo's integration policy (merge commit vs fast-forward vs rebase).
- Keep merge commits when the branch shape tells a useful story (long-running feature work).
- On conflicts: stop and report. Offer `git merge --abort` before attempting resolution.
## Reset and restore
- **Safe** (keeps file contents): `git restore --staged <file>`, `git reset --soft <ref>`.
@@ -0,0 +1,76 @@
# Evidence-First Git Recovery
Reference for `git-workspace`. Procedures for diagnosing and recovering lost commits, detached heads, botched rebases, or corrupted refs using observable evidence.
## Core Invariant
Never propose a destructive command (`git reset --hard`, `git checkout -f`, `git clean -fd`) as a speculative remedy. Destructive commands discard uncommitted files permanently. Always inspect evidence first, locate candidate commit SHAs, and restore state into a new named branch.
## 1. Inspect Current State Before Acting
Check working-tree and ref state:
```sh
git status --short
git branch -v
git log -n 5 --oneline
```
If working-tree changes exist, stash or commit them before attempting ref recovery:
```sh
git stash push -m "WIP before reflog recovery"
```
## 2. Reflog Inspection
The reflog records every update to local branch tips and `HEAD`.
- Inspect recent `HEAD` movements:
```sh
git reflog -n 20 --date=iso
```
- Look for state transitions:
- `rebase (finish)` / `rebase (start)`: find the commit immediately preceding `rebase (start)`.
- `reset: moving to ...`: find the SHA prior to the reset.
- `commit: ...`: locate orphaned commits from deleted or moved branches.
- Inspect branch-specific reflog:
```sh
git reflog show <branch-name>
```
## 3. Verify Candidate Commit
Inspect the candidate SHA before restoring:
```sh
git show <candidate-sha> --stat
git log -1 -p <candidate-sha>
```
Confirm that the commit contains the expected changes and history.
## 4. Non-Destructive Restoration
Never mutate current branch in place with `--hard` reset. Instead, point a dedicated recovery branch at the discovered SHA:
```sh
git branch recovery/<topic> <candidate-sha>
```
Verify the recovered branch:
```sh
git log -n 3 --oneline recovery/<topic>
```
Then switch to the recovery branch cleanly:
```sh
git switch recovery/<topic>
```
## 5. Dangling and Unreachable Objects (Last Resort)
If a commit was not captured in the reflog (e.g. reflog expired or repository corruption):
```sh
git fsck --lost-found
```
Dangling commits appear in `.git/lost-found/commit/`. Inspect each candidate:
```sh
git log -1 -p <dangling-sha>
```
Once found, create a branch off it:
```sh
git branch recovery/<topic> <dangling-sha>
```
@@ -0,0 +1,52 @@
# 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:
```sh
git worktree add ../<repo>-<branch> <branch>
```
- For a new branch off current base:
```sh
git worktree add -b feat/<name> ../<repo>-<feature> <base-ref>
```
### 2. Inspect Worktrees
- List all active worktree paths and their checked-out branches/SHAs:
```sh
git worktree list
```
### 3. Pinning / Locking
- Prevent accidental pruning when a worktree sits on removable or shared storage:
```sh
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:
```sh
git -C <path> status --short
```
- If clean, remove cleanly:
```sh
git worktree remove <path>
```
- If dirty, **never run `git worktree remove --force`** without explicit confirmation from the human owner describing what uncommitted edits will be discarded.
- If a worktree directory was deleted manually, clean up administrative metadata:
```sh
git worktree prune
```