Skip to content

Instantly share code, notes, and snippets.

@mvidner
Created February 11, 2026 10:25
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=("status" "diff")
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."
}
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'. Retry with the unwrapped git."
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