An AI-powered commit message generator that uses Ollama to create meaningful Git commit messages based on your staged changes.
- 🤖 AI-powered: Uses Ollama models to generate intelligent commit messages
- 📝 Conventional Commits: Optional support for conventional commit format
- 📋 Clipboard Integration: Automatically copy generated messages to clipboard
- 🎯 Context Aware: Add custom context to improve message generation
- 🏷️ Ticket Integration: Append ticket IDs to commit messages
- 🕑 Recent Commit & Branch Context: AI sees your last 3 commits and current branch for better relevance
- 🗂️ Diff Summarization: AI sees a summary of changed files for clarity
- 🔁 Message Regeneration: Accept or regenerate commit messages interactively
- ⚙️ Customizable Prompt Template: Uses an external
prompt.mdfile for the AI prompt, with full support for placeholders and user customization - 🛠️ Robust Placeholder Replacement: All placeholders in the prompt template (e.g.,
{gitStagedChanges},{branchName}) are replaced with real context
- Node.js (v14 or higher)
- Ollama installed and running
- Git repository with staged changes
- macOS, Windows or Linux
-
Clone the repository:
git clone https://github.com/madebygrant/commit-assist.git ~/scripts/commit-assist -
Navigate to the script directory:
cd ~/scripts/commit-assist
-
Install globally (this will also install dependencies):
npm install -g .
After global installation, you can use commit-assist from any directory in your terminal.
-
Clone the repository:
git clone https://github.com/madebygrant/commit-assist.git ~/scripts/commit-assist -
Navigate to the script directory and install dependencies:
cd ~/scripts/commit-assist npm install
-
Create a shell alias:
For Zsh (default on macOS):
echo 'alias commit-assist="node ~/scripts/commit-assist/commit-assist.js"' >> ~/.zshrc source ~/.zshrc
For Bash:
echo 'alias commit-assist="node ~/scripts/commit-assist/commit-assist.js"' >> ~/.bashrc source ~/.bashrc
Stage your changes with git add, then run:
commit-assist [options]-h, --helpShow help message-ctx, --context <text>Additional context for commit message-cf, --conventional-formatTell AI to use conventional commit format-t, --type <type>Custom conventional commit type-tid, --ticketid <ticket>Ticket id/number to append-c, --copyAutomatically copy to clipboard (no prompt)-m, --model <model>Specify Ollama model to use-pt, --prompt-template <path>Path to custom prompt template markdown file (overrides prompt.md)
Commit Assist can use an external prompt.md file as the default prompt for the AI. You can fully customize this file, or specify a custom prompt template file at runtime using the --prompt-template (or -pt) flag. For example:
commit-assist --prompt-template ./my-custom-prompt.mdYou can use the following placeholders in your template (these are required for full context):
{gitStagedChanges}— Output ofgit diff --cached --name-status, listing staged files and their status (A/M/D).{gitDiff}— Full unified diff of all staged changes (git diff --cached).{userContext}— Any extra context provided by the user.{recentCommits}— The last 3 commit messages from the current branch.{branchName}— The current git branch name.{gitDiffSummary}— A summary listing the names of files changed in the diff.{conventionalText}— Instruction for the AI to use or not use Conventional Commit format, depending on user options.
Note: Your custom template file must exist and be readable. Inline templates are not supported.
You are an expert at writing concise, high-quality Git commit messages.
- Write a single-line commit message (max 80 chars) in the imperative mood.
- Summarize the core change and, if possible, briefly state the reason ("why").
- Do not include "This commit", "Fixes", or similar phrases.
- Do not use markdown, lists, or extra formatting.
- If a ticket number is provided, do NOT include it in the message (it will be appended automatically).
- If the branch name or recent commits provide context, use it to avoid repetition.
- If the staged changes are trivial (e.g., formatting), mention that.
- {conventionalText}
Branch: {branchName}
Recent commits:
{recentCommits}
Staged changes:
{gitStagedChanges}
Diff summary:
{gitDiffSummary}
User context: {userContext}Basic commit message generation:
commit-assistWith context and conventional format:
commit-assist -cf -ctx "authentication issue"Auto-copy with ticket ID:
commit-assist -c -tid "PROJ-123"Custom model with specific type:
commit-assist -m "codellama:latest" -t "fix" -ctx "database connection"Custom prompt template file:
commit-assist -pt ./my-custom-prompt.mdFull example with all options:
commit-assist -m "llama3.2:latest" -cf -t "feat" -tid "PROJ-456" -ctx "add user authentication" -pt ./my-custom-prompt.md -c- Stage your changes with
git add - Run the script with desired options
- Review the generated commit message
- Copy to clipboard (automatically or when prompted)
- Commit using
git commit -m "paste_message_here"
The script determines which model to use in this order:
--modelor-mflag- Default:
llama3.2:latest
"No staged changes found"
- Make sure you have staged files with
git add <files> - Check
git statusto see staged changes
"Error generating commit message"
- Ensure Ollama is running:
ollama serve - Verify the model exists:
ollama list - Try a different model with
-mflag
"Clipboard copy failed"
- Cross-platform clipboard support provided by
clipboardy - If clipboard access fails, the message will still be displayed for manual copying
The script requires these npm packages:
ollama- Ollama API client for model interactionclipboardy- Cross-platform clipboard supportconsola- Elegant console output with interactive prompts
- Support for config files, global and project based
MIT License
Feel free to submit issues and pull requests to improve the script's functionality.