agentleFS
shalombshalomb/agent-skills/skills/git-safety-guardrails/SKILL.md

git-safety-guardrails

Skill3 starsChanged 3 months agoMITView on GitHub

Git safety guardrails for AI agents. Read before ANY git operation. Ensures GPG signing is never disabled, editors never launch interactively, and prompts are suppressed. Triggers on any git commit, rebase, merge, or tag operation.

  • Deletes or force-pushes
  • Commits and pushes

The file

We split this skill into the rules it gives an agent

8 rules. About 0 are common, 8 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈8

    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
  • could be automatic: a setting could enforce it
  1. Distinctive:

    Check signing is configured:

    line 14
  2. Distinctive:

    If the GPG key is locked (commit fails with "no secret key"), unlock it:

    line 20
  3. Distinctive:

    Do NOT work around a locked key by disabling signing.

    line 27
  4. Distinctive:

    When squash-merging a PR, GitHub squashes all commits on the branch that are not on the base branch — including any inherited history if …

    line 73
  5. Distinctive:

    If the branch was accidentally cut from a feature branch instead of main, the squash will swallow everything:

    line 87
  6. Distinctive:

    If a branch was cut from the wrong base and already has commits, cherry-pick the meaningful commits onto a fresh branch from main:

    line 98
  7. Distinctive:

    If a squash swallowed too much and landed on main:

    line 115
  8. Distinctive:

    Always force-push main with care — coordinate with the team first.

    line 129

≈ “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.

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

Git — Agent Safety Guardrails

Before any git operation

1. GPG signing must stay enabled

Never run git config commit.gpgsign false or --no-gpg-sign.

Check signing is configured:

git config --get commit.gpgsign  # must be "true"
git config --get user.signingkey  # must be non-empty

If the GPG key is locked (commit fails with "no secret key"), unlock it:

export GPG_TTY=$(tty)
echo "test" | gpg --batch --pinentry-mode loopback -o /dev/null --sign - \
  || echo "⚠️ GPG key locked — ask user to unlock with: gpg --sign /dev/null"

Do NOT work around a locked key by disabling signing. Stop and ask.

2. Prevent interactive editors

Set these before any rebase, merge, or commit that might launch an editor:

export GIT_EDITOR=true
export GIT_SEQUENCE_EDITOR=true
export EDITOR=true
export VISUAL=true

true is the no-op binary — it exits 0 without launching anything.

For interactive rebase, always prepare the todo file and pipe it:

GIT_SEQUENCE_EDITOR="sed -i 's/^pick \(HASH\)/edit \1/'" git rebase -i HEAD~3

3. Suppress prompts

export GIT_TERMINAL_PROMPT=0
export GIT_ASK_YESNO=false

4. Pager safety

export GIT_PAGER=cat    # or leave as delta if configured

Quick pre-flight

Copy-paste before a git-heavy session:

export GPG_TTY=$(tty)
export GIT_EDITOR=true GIT_SEQUENCE_EDITOR=true EDITOR=true VISUAL=true
export GIT_TERMINAL_PROMPT=0 GIT_ASK_YESNO=false

Squash merge gotcha: check the branch base before merging

When squash-merging a PR, GitHub squashes all commits on the branch that are not on the base branch — including any inherited history if the branch was cut from the wrong point.

Before every squash merge, verify the diff is only what you intend:

# Three-dot diff = only what this branch uniquely adds
git diff origin/main...HEAD --stat

# Count of commits that will be squashed
git log --oneline origin/main..HEAD | wc -l

If the branch was accidentally cut from a feature branch instead of main, the squash will swallow everything:

# WRONG — feature-branch cut from another feature branch
git checkout -b ci/my-change some-feature-branch  # ← inherits 30 commits

# RIGHT — always cut from the actual base
git checkout -b ci/my-change origin/main

If a branch was cut from the wrong base and already has commits, cherry-pick the meaningful commits onto a fresh branch from main:

# Identify the commits that actually matter
git log --oneline origin/main..HEAD  # these are the commits to cherry-pick

# Create clean branch from correct base
git checkout -b ci/my-change-clean origin/main
git cherry-pick <sha1> <sha2>       # only the real work

# Verify
git diff origin/main...HEAD --stat  # should be minimal and correct

Reverting a bad squash merge from main

If a squash swallowed too much and landed on main:

# Identify the bad commit
git log --oneline origin/main -3

# Reset locally
git checkout main && git pull
git reset --hard <sha-before-bad-commit>

# Force push (confirm no one else has pulled the bad state)
git push origin main --force

Always force-push main with care — coordinate with the team first.

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.