Git Under Contention
Preserve every participant's work when repository state may change concurrently.
Core rule
Treat shared checkout as contested state. Stage exact paths, commit only owned changes, and leave unfamiliar hunks untouched.
Preflight
Run bundled detector before first commit in shared checkout:
python <skill-dir>/scripts/contention_preflight.py
python <skill-dir>/scripts/contention_preflight.py --mine path/owned-by-task
Signals include registered worktrees, recent HEAD movement, pre-staged files, and dirty paths outside owned pathspecs. CONTENTION is not automatic failure – it means use isolated worktree or stricter path ownership.
Skip detector only inside isolated worktree created for current task and still run normal status checks.
Shared-checkout rules
- Inspect
git status --porcelain, current branch, top-level path, and staged diff before mutation.
- Stage with
git add <path>...; avoid git add ., git add -A, and git commit -a.
- Review
git diff --cached --name-only and git diff --cached before commit.
- Commit with explicit pathspec when repository conventions allow it.
- Leave changes outside owned paths unchanged, staged or unstaged.
- Avoid stash in contested checkout because stash captures shared state. Use task worktree or WIP commit on owned branch.
- Fetch before deciding branch freshness; do not reset shared checkout to match remote.
- Push durable work promptly so recovery does not depend on one disk.
Worktree lifecycle
Prefer worktree per task when work is multi-file, long-running, risky, or parallel.
- Fetch remote and create short-lived branch from intended base.
- Create worktree at explicit validated path.
- Record absolute root, branch, and base commit in handoff.
- Edit, stage exact paths, commit, and push as one durable sequence.
- Recheck dirty state and unpushed commits before cleanup.
- Remove worktree only through repository helper when one exists.
Before recursive worktree cleanup, inspect symlinks, junctions, mounts, and dependency links. Remove links safely before recursive deletion so cleanup cannot traverse into another checkout.
When state moves unexpectedly
- File disappears: verify
git rev-parse --show-toplevel, branch, and HEAD before recreating it.
- HEAD changes during read-only audit: re-anchor findings to new HEAD.
- Staged files appear: inspect and preserve; do not unstage unless ownership is known.
- Push rejected as behind remote: fetch, inspect divergence, and integrate only owned branch.
- Worktree vanishes: recover from pushed branch or commits; do not guess from stale local paths.
- Generated file conflicts: regenerate once at repository-defined integration point instead of hand-merging machine output.
Safe handoff
Report:
Repo root: <absolute path>
Branch: <name>
Base: <sha>
Pushed tip: <sha or not pushed>
Owned paths: <list>
Dirty paths remaining: <list>
Other work preserved: <summary>
Next command: <single concrete action>
Checklist before push
Stop conditions
- Destructive reset, force-push, branch deletion, or worktree deletion could affect unowned state.
- Required file contains fresh hunks from another active task and safe merge cannot be proven.
- Target path for recursive cleanup contains unresolved links, junctions, mounts, or escapes intended workspace.
Ask owner for coordination rather than racing these conditions.
Bundled resource
scripts/contention_preflight.py provides deterministic CLEAR or CONTENTION verdict, JSON output, and hermetic --selftest.
Related skills
session-close makes work durable before session ends.
verify-honestly prevents false claims about pushed or merged state.
1---2name: git-under-contention3description: Operate Git safely when multiple humans or coding agents may share a repository, checkout, index, branches, or worktrees. Use before staging, committing, pushing, merging, rebasing, creating or removing worktrees, recovering apparently lost edits, handling staged files you did not touch, or preserving unfinished agent work under parallel-session contention.4---56# Git Under Contention78Preserve every participant's work when repository state may change concurrently.910## Core rule1112Treat shared checkout as contested state. Stage exact paths, commit only owned changes, and leave unfamiliar hunks untouched.1314## Preflight1516Run bundled detector before first commit in shared checkout:1718```bash19python <skill-dir>/scripts/contention_preflight.py20python <skill-dir>/scripts/contention_preflight.py --mine path/owned-by-task21```2223Signals include registered worktrees, recent HEAD movement, pre-staged files, and dirty paths outside owned pathspecs. `CONTENTION` is not automatic failure – it means use isolated worktree or stricter path ownership.2425Skip detector only inside isolated worktree created for current task and still run normal status checks.2627## Shared-checkout rules2829- Inspect `git status --porcelain`, current branch, top-level path, and staged diff before mutation.30- Stage with `git add <path>...`; avoid `git add .`, `git add -A`, and `git commit -a`.31- Review `git diff --cached --name-only` and `git diff --cached` before commit.32- Commit with explicit pathspec when repository conventions allow it.33- Leave changes outside owned paths unchanged, staged or unstaged.34- Avoid stash in contested checkout because stash captures shared state. Use task worktree or WIP commit on owned branch.35- Fetch before deciding branch freshness; do not reset shared checkout to match remote.36- Push durable work promptly so recovery does not depend on one disk.3738## Worktree lifecycle3940Prefer worktree per task when work is multi-file, long-running, risky, or parallel.41421. Fetch remote and create short-lived branch from intended base.432. Create worktree at explicit validated path.443. Record absolute root, branch, and base commit in handoff.454. Edit, stage exact paths, commit, and push as one durable sequence.465. Recheck dirty state and unpushed commits before cleanup.476. Remove worktree only through repository helper when one exists.4849Before recursive worktree cleanup, inspect symlinks, junctions, mounts, and dependency links. Remove links safely before recursive deletion so cleanup cannot traverse into another checkout.5051## When state moves unexpectedly5253- File disappears: verify `git rev-parse --show-toplevel`, branch, and HEAD before recreating it.54- HEAD changes during read-only audit: re-anchor findings to new HEAD.55- Staged files appear: inspect and preserve; do not unstage unless ownership is known.56- Push rejected as behind remote: fetch, inspect divergence, and integrate only owned branch.57- Worktree vanishes: recover from pushed branch or commits; do not guess from stale local paths.58- Generated file conflicts: regenerate once at repository-defined integration point instead of hand-merging machine output.5960## Safe handoff6162Report:6364```text65Repo root: <absolute path>66Branch: <name>67Base: <sha>68Pushed tip: <sha or not pushed>69Owned paths: <list>70Dirty paths remaining: <list>71Other work preserved: <summary>72Next command: <single concrete action>73```7475## Checklist before push7677- [ ] Current root, branch, and HEAD confirmed.78- [ ] Staged paths belong only to current task.79- [ ] Cached diff reviewed.80- [ ] Unfamiliar working-tree changes preserved.81- [ ] Generated artifacts handled at canonical integration point.82- [ ] Branch pushed and remote tip confirmed.83- [ ] Cleanup skipped until worktree is clean and durable.8485## Stop conditions8687- Destructive reset, force-push, branch deletion, or worktree deletion could affect unowned state.88- Required file contains fresh hunks from another active task and safe merge cannot be proven.89- Target path for recursive cleanup contains unresolved links, junctions, mounts, or escapes intended workspace.9091Ask owner for coordination rather than racing these conditions.9293## Bundled resource9495`scripts/contention_preflight.py` provides deterministic `CLEAR` or `CONTENTION` verdict, JSON output, and hermetic `--selftest`.9697## Related skills9899- `session-close` makes work durable before session ends.100- `verify-honestly` prevents false claims about pushed or merged state.