git-under-contention
Skill7 starsChanged 6 months agoMITView on GitHub
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.
In this repository6 other files it gives its agents.
- AGENTS.mdAGENTS.md
- codex-promptSkill
- gate-engineeringSkill
- retro-distillSkill
- session-closeSkill
- verify-honestlySkill
The file
We split this skill into the rules it gives an agent
10 rules. About 0 are common, 10 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈10
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 14
Treat shared checkout as contested state.
- Distinctive: line 18
Run bundled detector before first commit in shared checkout:
- Distinctive: line 34
Commit with explicit pathspec when repository conventions allow it.
- Distinctive: line 35
Leave changes outside owned paths unchanged, staged or unstaged.
- Distinctive: line 36
Avoid stash in contested checkout because stash captures shared state.
- Distinctive: line 42
Prefer worktree per task when work is multi-file, long-running, risky, or parallel.
- Distinctive: line 45
Create worktree at explicit validated path.
- Distinctive: line 49
Remove worktree only through repository helper when one exists.
- Distinctive: line 51
Before recursive worktree cleanup, inspect symlinks, junctions, mounts, and dependency links.
- Distinctive: line 93
Ask owner for coordination rather than racing these conditions.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
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-taskSignals 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>...; avoidgit add .,git add -A, andgit commit -a. - Review
git diff --cached --name-onlyandgit diff --cachedbefore 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
- Current root, branch, and HEAD confirmed.
- Staged paths belong only to current task.
- Cached diff reviewed.
- Unfamiliar working-tree changes preserved.
- Generated artifacts handled at canonical integration point.
- Branch pushed and remote tip confirmed.
- Cleanup skipped until worktree is clean and durable.
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-closemakes work durable before session ends.verify-honestlyprevents false claims about pushed or merged state.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

