Skip to content

Instantly share code, notes, and snippets.

@skorotkiewicz
Created August 26, 2025 05:03
Show Gist options
  • Save skorotkiewicz/16e9fb283dbcdf1839072af97f9b8f59 to your computer and use it in GitHub Desktop.
Save skorotkiewicz/16e9fb283dbcdf1839072af97f9b8f59 to your computer and use it in GitHub Desktop.
Commit git with Ollama
#!/usr/bin/env sh
# Make this file executable: chmod +x .git/hooks/prepare-commit-msg
echo "Running prepare-commit-msg hook"
COMMIT_MSG_FILE="$1"
# Get the staged diff
DIFF=$(git diff --cached)
# Generate a summary with ollama CLI and gemma3 model
SUMMARY=$(
ollama run gemma3 <<EOF
Generate a raw text commit message for the following diff.
Keep commit message concise and to the point.
Make the first line the title (100 characters max) and the rest the body:
$DIFF
EOF
)
if [ -f "$COMMIT_MSG_FILE" ]; then
# Save the AI generated summary to the commit message file
echo "$SUMMARY" >"$COMMIT_MSG_FILE"
# Append existing message if it exists
if [ -n "$EXISTING_MSG" ]; then
echo "" >>"$COMMIT_MSG_FILE"
echo "$EXISTING_MSG" >>"$COMMIT_MSG_FILE"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment