agentleFS
TrueImmortal82TrueImmortal82/open-code-skills/skills/git-safety/SKILL.md

git-safety

Skill0 starsChanged 41 days agoMITView on GitHub

Run a reversible preflight before git commands that discard work, and recover work that was already lost. Use when about to run `git reset --hard`, `git checkout .`, `git restore`, `git clean -fd`, `git branch -D`, `git rebase`, `git push --force`, or `git stash`; when a command would delete untracked or uncommitted work; when checking whether the working tree is safe to modify; or when someone says git lost their changes. Ships scripts/git-preflight.mjs, which reports dirty, untracked, unpushed, and remote-only state, and marks each destructive command ok, LOST, or ?.

  • Deletes or force-pushes
  • Commits and pushes

11 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use verification-before-completion.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • OpenAISkill

    verification-before-completion

    Use when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions always

    Also in 3 projects that use this

The file

We split this skill into the rules it gives an agent

5 rules. 0 are common, 2 are distinctive, and 3 are very specific to this project.

  • 0

    Common

    Most of the 11 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Before reset --hard, checkout ., clean -fd, branch -D, rebase, push --force, or stash.

    line 14
  2. Distinctive:

    When a command would delete untracked or uncommitted work.

    line 16
  3. Distinctive:

    When work was already lost and you are looking for where it went.

    line 17
  4. Very specific:

    The reversible spelling is the default spelling: Prefer, in order: git stash over checkout ..

    line 23
  5. Very specific:

    A commit is not lost until nothing references it: After a bad reset, look at git reflog before concluding anything: the commit is usually …

    line 37

“Common” is measured: kept by at least 6 in 10 of the 11 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Git safety

Most git data loss is not a git bug. It is a destructive command run without knowing what was in the tree. The fix is boring: look first, and prefer the reversible spelling.

When to use this

  • Before reset --hard, checkout ., clean -fd, branch -D, rebase, push --force, or stash.
  • When a command would delete untracked or uncommitted work.
  • When work was already lost and you are looking for where it went.

Rules

  1. Look before destroying. git status --porcelain first, every time. The cost is one command; the alternative is an afternoon.
  2. The reversible spelling is the default spelling. Prefer, in order: git stash over checkout .; git restore <file> over reset --hard; git branch -d over -D; git push --force-with-lease over --force; git rebase --abort availability over starting one.
  3. Untracked files are the ones that vanish. clean -fd deletes work that was never committed, so there is nothing to restore from. Committed work is recoverable from the object store; untracked work is simply gone.
  4. An empty directory is invisible to git status but not to git clean. Git does not track directories, so an empty folder never shows as untracked and clean -fd still removes it. This is the one case where clean -nd reports something status does not. Believe the dry run.
  5. Force-push is only safe when the remote has not moved. --force-with-lease refuses when the remote has commits you have not fetched. Plain --force overwrites them, including someone else's work.
  6. A commit is not lost until nothing references it. After a bad reset, look at git reflog before concluding anything: the commit is usually still there for weeks. git reset --hard <sha> brings it back.

Preflight

node scripts/git-preflight.mjs [dir] [--json] [--quiet]

Reports staged, unstaged, untracked, conflicted, clean-dry-run, ignored, unpushed, and remote-only state, then marks each common destructive command ok, LOST, or ? for the tree as it is right now.

? means the tree state cannot decide it — git branch -D depends on the named branch and on other remotes. Check that branch specifically rather than reading ? as permission.

Exit codes: 0 nothing at risk, 1 work would be lost, 2 not a git tree.

node scripts/git-preflight.mjs            # human report
node scripts/git-preflight.mjs --json     # for a script or a hook

The script only reads. git clean -nd and -ndX are dry runs, so running the preflight never removes anything.

Recovering lost work

In order, cheapest first:

git reflog                      # find the sha the commit was on
git reset --hard <sha>          # or: git checkout -b rescue <sha>
git stash list                  # for work parked by a stash
git fsck --lost-found           # last resort, for unreachable objects

Reach for reflog before redoing the work. It is nearly always still there, and retyping a lost change is strictly worse than a command that seems scary.

When a command must be irreversible anyway

State what is lost before running it, not after. If the answer is "the two untracked files draft.md and notes.txt", say that in one line, then run it. An unannounced destructive command is the actual defect, not the command.

Checklist

  • Ran git status --porcelain or the preflight first
  • Chose the reversible spelling where one existed
  • Checked untracked files, which have no recovery path
  • Used --force-with-lease rather than --force
  • Said out loud what the irreversible command would lose
  • Did not conclude data was lost before checking git reflog

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.