git_safety — Claude Code prompt: safe Git
git_safety is a Claude Code prompt that keeps Git work inside the correct repository. It stops when a task would move code or rewrite a remote.
MIT ★ 341 updated 2026-11-17
.claude/commands/git_safety.mdWhat git_safety does
git_safety sets a repository boundary for Git work. Commits and pushes can target only the repository's existing origin and current branch, while each checkout keeps its own history.
The prompt blocks remote changes, pushes to arbitrary URLs, force pushes, and mirror pushes. It also forbids moving commits or files through cross-repository git cherry-pick, git format-patch, git am, merges, or copied .git directories. Work stays inside the repository's own checkout. When an operation requires one of these actions, the prompt tells the agent to stop and explain why.
What it helps with
- keep commits on the repository's current
origin - prevent code from crossing repository boundaries
- block remote rewrites and arbitrary push targets
- stop cross-repository cherry-picks and merges
Example prompts for the agent
- Work only inside this repository's checkout and push changes to its existing
origin. - Check whether this operation would move commits or files between repositories.
- Stop and explain the reason if the task requires a force push, remote change, or copied
.gitdirectory.
How to install git_safety
Manually: put the files in place
.claude/commands/git_safety.mdHow to use
Paste the text at the start of a chat or into project instructions
Questions about git_safety
How do I install git_safety in Claude Code?
Place the prompt in .claude/commands/git_safety.md.
What does git_safety do?
It keeps Git operations within the source repository, allowing commits and pushes only to that repository's current origin while blocking code transfers between repositories.
Which Git operations does git_safety block?
It blocks adding, changing, renaming, or removing remotes, editing remote settings in .git/config, arbitrary push URLs, force pushes, and mirror pushes. Cross-repository git cherry-pick, git format-patch, git am, merges, and copied .git directories are blocked too.
Source text
git_safety.md · MIT
# Git safety — never leak code across repositories Code from one repository must **never** end up in another. This is critical and overrides any convenience. - Commit and push **only** to each repository's own existing `origin`, on its current branch. Never change where a repository points. - **Never** run remote-rewriting or otherwise disruptive git, including: `git remote set-url`, `git remote add`, `git remote rename`, `git remote remove`, editing `.git/config` remotes, `git push` to an arbitrary URL, or `--force` / `--mirror` pushes. - **Never** move commits or files between repositories — no cross-repo `git cherry-pick`, `git format-patch` / `git am`, cross-repo `git merge`, or copying one repo's `.git` into another. Each repository's history stays its own. - Operate each repository strictly inside its own checkout directory; never point one repo's git at another repo's path or remote. If you cannot address an item without one of these, **stop and tell the user why** instead of doing it.
© rudderlabs · MIT · rudderlabs/devbox