Skip to content
Skills Library
Programming · Review & audit

git-efficiency

/git-efficiency

Use git efficiently and safely from scripts and agents, on slow mounts (WSL drvfs, network) or in repos several agents share. Use when writing, reviewing or auditing code that shells out to git, when git is slow or hits `index.lock`, or when one agent's commit sweeps up another's files.

Licence
MIT
Last repository change
11.11.2026

Assessment and security

90/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content25 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
14
Scripts
7
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 11.11.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What to check before installing
  • 7 scripts in this package. Review them before installing, as Claude may execute them.

Scripts: eval/evalinputs/bad_git_script.py, eval/git-efficiency-workspace/grade.py, eval/git-efficiency-workspace/iteration-1/eval-rename/with_skill/outputs/rename_mods.py, eval/git-efficiency-workspace/iteration-1/eval-rename/without_skill/outputs/rename_mods.py, eval/git-efficiency-workspace/iteration-1/eval-status/with_skill/outputs/file_git_info.py, eval/git-efficiency-workspace/iteration-1/eval-status

What it does and when to use it

Use git efficiently and safely from scripts and agents, on slow mounts (WSL drvfs, network) or in repos several agents share. Use when writing, reviewing or auditing code that shells out to git, when git is slow or hits `index.lock`, or when one agent's commit sweeps up another's files.

Triggers from the description

s commit sweeps up another
Original author description

Use git efficiently and safely from scripts and agents, on slow mounts (WSL drvfs, network) or in repos several agents share. Use when writing, reviewing or auditing code that shells out to git, when git is slow or hits `index.lock`, or when one agent's commit sweeps up another's files.

How it works

  1. Batch
  2. Trust the exit code for success, not for scope
  3. Safety on a shared worktree
  4. Filesystem operations beat git plumbing
  5. Auditing existing code
  6. Checklist
Original SKILL.md headings · 166 lines, 1,394 words
SKILL.md preview
---
name: git-efficiency
description: >-
  Use git efficiently and safely from scripts and agents, on slow mounts (WSL
  drvfs, network) or in repos several agents share. Use when writing, reviewing
  or auditing code that shells out to git, when git is slow or hits
  `index.lock`, or when one agent's commit sweeps up another's files.
---

# Engaging git efficiently and safely

Every `git ...` is a **process spawn** (fork, load binary, read config). On a
slow mount that costs tens to hundreds of ms, so a per-file loop scales linearly
with file count. And every command that **writes the index** (`add`, `commit`,
`mv`, `rm`, `checkout`, `reset`, `merge`, `stash`) takes `.git/index.lock`
exclusively; in a shared repo serial per-file writes thrash that lock and other
agents fail with *"Unable to create '.../index.lock': File exists"*. Pure reads
(`log`, `show`, `cat-file`, `rev-parse`) take no lock; `status` refreshes the
index only opportunistically and does not fail on a held lock.

So: **do the fewest git invocations that accomplish the task, scope every one
explicitly, and never hold the lock across a loop.**

## Batch

**Stage many paths in one call:** `git add a b c`, not a loop of `git add "$f"`.
In a script, collect paths and pass them together (`git add -- "${paths[@]}"`,
`subprocess.run(["git","add","--",*paths])`). Thousands of pathspecs in one call
are far faster than thousands of calls.

⚠️ **zsh does not word-split an unquoted variable.** `paths="a b c"; git add
$paths` passes ONE pathspec and fails. Use a real array (`"${paths[@]}"`) or
`${=paths}`, not a per-path loop.

**Ask about many things in one call:**
- `git status --porcelain` once and parse, never `git status <path>` per path.
- `git log --name-only` / `--name-status` for files-per-commit in one walk.
- `git cat-file --batch` for many objects, not `git show <rev>:<path>` each.
- `git diff --cached --name-only` once for the staged set.

**Bound history walks** (`-n 1`, `--max-count`, `--since`) when you don't need
all of it. **Read constants once** (`rev-parse HEAD`, `config`,
`--show-toplevel`); don't re-shell them in a loop.

More traps for this section: [references/traps.md](references/traps.md) § Batch.

## Trust the exit code for success, not for scope

A `git add` / `commit` / `mv` that exits 0 did what you asked; don't re-run
`status` or `log` to "make sure". Exit 0 does not prove you asked for the right
scope, so check state only where scope can silently differ from intent: the
partial-commit and lock-retry cases flagged below.

## Safety on a shared worktree

**Never bare `git commit` / `commit -a`, never `git add -A` / `git add .`.** A
bare commit takes the whole index, including files another agent staged; `-A`
stages the whole tree (a full-tree stat on a slow mount, and it sweeps up others'
work). Name files, not directories: a directory pathspec commits everything under
it, including what a daemon or peer wrote there since.

**Default commit form: `git commit -m "msg" -- <paths>`.** It commits only the
named paths whatever else is staged, which is why it is the default in a shared
index. **`-m` must come before `--`**, or the message is read as a pathspec.

🔴 **A pathspec commit takes each named file's WORKING-TREE content, not its
staged content.** Paths isolate files, not hunks or authors: an unrelated unstaged
edit to a named file is committed too. So:
- Before `git commit -m "msg" -- <paths>`, check `git diff -- <path>` (unstaged
  changes) shows nothing, or only changes you mean to commit.
- If you staged hunks deliberately (`add -p`) and the file has other unstaged
  edits, commit the staged content with plain `git commit -m "msg"` (no
  pathspec), right after confirming `git diff --cached --name-only` lists only
  your paths.

**A pathspec commit refuses an untracked path** ("did not match any file(s)
known to git"). `git add` a new file first.

**A rename stages a deletion and a creation: name both ends.** Committing only
the new path leaves the old-path deletions staged.

**A staged path left out of a multi-path `git commit -- <paths>` stays staged,
silently, and rides into later commits.** After such a commit, `git status
--short -- <every path you touched>` must be clean.

**Stage and commit back to back.** Between a separate `add` and `commit`, another
agent's commit can sweep your staged files under their message. If a commit says
"no changes added to commit" right after a successful `add`, check whether your
change already landed in HEAD before re-adding.

**Never suppress stderr on `add`/`commit`.** One bad path can reject the whole
`add`; with `2>/dev/null` you commit nothing while believing you staged
everything.

**Never stash, `pull --rebase --autostash`, rebase or merge in a tree others are
editing**, nor while your own subagents are mid-edit. Each can drop someone's
uncommitted work, and a refused `git merge` can hard-reset the tree. Merge in a
private worktree and push `HEAD:<branch>` from there. Commit and push the moment
work exists. If work looks lost, or you must publish from a tree that is never
clean, or a pushed commit tells the wrong story, read
[references/shared-tree-recovery.md](references/shared-tree-recovery.md).

**Cherry-picking onto a file someone has since reformatted** (e.g. JSON
re-serialized in a different key order) conflicts with context that looks
unrelated. Don't fight the textual merge:
1. `git show <sha> -- <file>` to read the small semantic change.
2. `git checkout --ours <file>` to take the current-format file.
3. hand-apply the semantic change onto it.
4. `git add <file>` to mark it resolved.
5. `git cherry-pick --continue`.

**Handle `index.lock`; don't fight it.**
- Assume a **live** git first: `pgrep -f 'git '`, `fuser .git/index.lock`, the
  lock's age. If something is mid-write, wait.
- **On WSL, also check Windows** (`tasklist.exe | grep -i '^git'`): a Windows
  git.exe holding the lock is invisible to Linux `pgrep`.
- Remove it (`rm -f .git/index.lock`) only when stale: no live git on either side
  and older than any plausible command. A retry loop that re-checks liveness
  (~15-20 tries at 2 s) clears real contention safely.
- Never wrap git calls in a blind `rm -f index.lock`; it corrupts a live writer.
- **After a contention retry succeeds, `git log --stat -1` what landed.** A
  failed `add` can leave stale staged content that a later commit ships.

**Don't hold the lock across a loop.** Do per-item work without git (moves,
building a list), then one batched git call at the end.

**Structural fix: per-agent worktrees.** Agents sharing one worktree share one
index, so batching can't remove all contention; `git worktree add` gives each its
own. Worktrees don't isolate brief wording, globs or import paths; see
`parallel-agent-worktrees`.

More traps for this section: [references/traps.md](references/traps.md) § Safety on a shared worktree.

## Filesystem operations beat git plumbing

**Renames:** move with the filesystem (`os.replace`, `mv`), then one batched
`git add -- <old paths> <new paths>`; git detects renames from content. Where a
guard blocks `git add -A`, `git rm -r --cached --quiet -- <old paths>` then
`git add -- <new paths>` stages a batch of renames in two calls; `git status`
should show `R` entries.

**Test fixtures: build the repo once** per test file (template repo with a base
commit), then copy the tree or reset it per case, instead of `init` + `config` +
`add` + `commit` in every case.

More traps for this section: [references/traps.md](references/traps.md) § Filesystem operations beat git plumbing.

## Auditing existing code

- **Grep for `git` over-reports**: most hits are comments, help text and print
  strings. Read the call site (in a loop? what bound?) before flagging.
- **Impact = loop bound** x git commands per iteration.
- **Don't flag a single batched call.** Flag per-item loops, unbounded walks, and
  safety holes (bare commit, `-A`, suppressed stderr, pathspec commit over
  unrelated unstaged hunks).
- **Separate slowness from entanglement.** Per-case `git init` in a temp repo is
  only spawn cost; a per-row `git mv` in the shared repo is also a collision risk
  and outranks it even at smaller N.

More traps for this section: [references/traps.md](references/traps.md) § Auditing existing code.

## Checklist

- [ ] No mutating git command per file where one batched call would do.
- [ ] `status` / `log` / object reads are one call over many items.
- [ ] Every `commit` and `add` names explicit files: no bare commit, no `-A`/`.`.
- [ ] Pathspec commits only over files with no unrelated unstaged hunks.
- [ ] No `2>/dev/null` on `add`/`commit`.
- [ ] History walks bounded when you don't need all of it.
- [ ] Constants (`rev-parse HEAD`, config) read once.
- [ ] Per-item work outside the lock; git taken once at the end.
- [ ] Stale-lock handling tells a live git from a dead one before removing.
- [ ] Many agents still colliding: consider worktrees.
Files in this package (14)
  • README.md 1 KB
  • SKILL.md 9 KB
  • eval/EVAL_RESULTS.md 2 KB
  • eval/evalinputs/bad_git_script.py 1 KB
  • eval/git-efficiency-workspace/grade.py 4 KB
  • eval/git-efficiency-workspace/iteration-1/eval-audit/with_skill/outputs/review.md 3 KB
  • eval/git-efficiency-workspace/iteration-1/eval-audit/without_skill/outputs/review.md 4 KB
  • eval/git-efficiency-workspace/iteration-1/eval-rename/with_skill/outputs/rename_mods.py 4 KB
  • eval/git-efficiency-workspace/iteration-1/eval-rename/without_skill/outputs/rename_mods.py 4 KB
  • eval/git-efficiency-workspace/iteration-1/eval-status/with_skill/outputs/file_git_info.py 5 KB
  • eval/git-efficiency-workspace/iteration-1/eval-status/without_skill/outputs/file_git_info.py 3 KB
  • references/shared-tree-recovery.md 3 KB
  • references/traps.md 7 KB
  • tests/test_review_2026_10_15.py 7 KB

Versions

The database has no other skills named git-efficiency.

Database snapshot: 13.11.2026 · package version f16d3b1a9438 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 90parallel-agent-git
    Commit safely when several AI agents (parallel Claude Code sessions, loops, sub-agents) share ONE git working tree and index. Commits only your own paths, never sweeps another agent's staged or unfinished files, never uses git stash, and leaves the shared index clean. Use…
  • 100git-commit
    Guide for Git commit messages and pushing code. Use when user says "commit", "push code", "push to git", "save changes to git", "git add and commit", "commit and push", or needs help writing commit messages following Conventional Commits.
  • 92git-commit
    Use when creating Git commits.
  • 100commit
    Use when creating a git commit — the user asks to commit, or a unit of work is complete and ready to commit.
  • 100git-commit-helper
    基于本次任务的变更执行 git add 与 git commit,产出"类型: 一句话简述"格式的简洁中文提交信息;多阶段任务拆分为多次提交。仅在用户明确下达提交指令时使用(如"提交"、"commit"、"把这些变更提交一下")——任何情况下都不得自动提交,未获明确指令时只汇报变更、不动 git。
  • 100git-commit
    Use this skill when user asks to "commit changes", "create a commit", "stage and commit", or wants help with git commit workflow.

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.