Skip to content

Instantly share code, notes, and snippets.

@mvidner
Last active March 16, 2026 16:29
Show Gist options
  • Select an option

  • Save mvidner/2f018beb6d44a1355188596d5de36c1e to your computer and use it in GitHub Desktop.

Select an option

Save mvidner/2f018beb6d44a1355188596d5de36c1e to your computer and use it in GitHub Desktop.
#!/bin/bash
SAFE_SUBCOMMANDS=("diff" "log" "ls-files" "show" "status")
show_help() {
echo "Usage: llm-git <subcommand> [options]"
echo ""
echo "A wrapper for git that only allows safe commands to be run by an LLM."
echo ""
echo "Allowed subcommands:"
for cmd in "${SAFE_SUBCOMMANDS[@]}"; do
echo " - $cmd"
done
echo ""
echo "Options:"
echo " -h, --help - Display this help message and exit"
echo ""
echo "For other git commands, please use 'git' directly."
cat <<EOF
Instructions for LLMs:
The user considers git a sensitive command and wants to manually
approve running it. But certain git subcommands are OK to be run
without approval.
Therefore, whenever you want to run git, run llm-git instead.
If llm-git fails and you fall back to git, do it only once.
The next time, try llm-git again.
EOF
}
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
show_help
exit 0
fi
SUBCOMMAND=$1
is_safe=false
for safe_command in "${SAFE_SUBCOMMANDS[@]}"; do
if [[ "$SUBCOMMAND" == "$safe_command" ]]; then
is_safe=true
break
fi
done
# If the subcommand is safe, execute the git command with all arguments.
if $is_safe; then
git "$@"
else
if [[ -n "$SUBCOMMAND" ]]; then
echo "Disallowed subcommand '$SUBCOMMAND'. Use 'git $SUBCOMMAND'. Keep using llm-git for other subcommands."
else
show_help # Show help if no subcommand is given
fi
exit 1
fi
@mvidner
Copy link
Author

mvidner commented Feb 11, 2026

For GEMINI.md:

If you want to run git, run llm-git instead.
At the start, run llm-git --help to learn about it.

This lets you "Always allow llm-git" while keeping manual control over git commit and such.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment