Last active
March 16, 2026 16:29
-
-
Save mvidner/2f018beb6d44a1355188596d5de36c1e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For GEMINI.md:
This lets you "Always allow
llm-git" while keeping manual control overgit commitand such.