Building clear, concise commit messages can feel like a chore—especially when you’ve got context switching, PR reviews, and deadlines breathing down your neck. GitHub Copilot’s “generate commit” feature is handy, but you may hit retry limits or find that it simply won’t fire off a good message.
Enter Codestral, an AI‑powered chat API from Mistral that you can hook into your local workflow with a single shell script. Below, we’ll walk through:
- Why you might look beyond Copilot for commit messages
- How to grab your free Codestral API key
- A drop‑in
.sh
script you can drop into your repo to generate and confirm AI‑crafted commit messages
1. When Copilot’s “Generate Commit” Hits Its Limit or Windsurf "is only available for users on a paid plan"
Copilot is great—and for many small changes, it nails the message on the first try. But if you:
- Push the “retry” button too many times
- Get rate‑limited mid‑flow
- Find its output too verbose or vague
- Source: Windsurf
AI commit message generation is only available for users on a paid plan.
By using an external AI backend via a simple curl
call, you sidestep GitHub’s limits and get ultra‑low‑latency responses fine‑tuned for commit messages.
Hint: You could replace the codestral api with any other OpenAI-compatible API and model. Only replace:
- CODESTRAL_API_KEY -> FOO_API_KEY
- DEFAULT_MODEL=foo-latest
- API_URL=https://my.foo.ai/v1/chat/completions
2. Grab Your Free Codestral Key
Sign up for a free API key at Mistral’s console:
You’ll be prompted to log in or create an account, then copy your Codestral API key—a long alphanumeric token that you’ll stash in an environment variable or .env
file.
3. Drop‑in Shell Script: ai-git-commit.sh
Below is an alternative to GitHub Copilot AI commit message generator. Save this as scripts/ai-git-commit.sh
(or wherever you keep your helper scripts), make it executable, and watch it auto‑stage, summarize diffs, call Codestral, and prompt you for confirmation.
How it works:
- Staging: Automatically stages tracked changes, with an optional prompt for untracked files.
- Diffing: Pulls in your staged diff (up to ~6,000 characters).
- Payload: Wraps the diff in a JSON payload for the Codestral chat endpoint.
-
API call: Sends
model: codestral-latest
with low temperature to get a focused message. - Cleanup: Strips Markdown fences and polish quotes.
- Confirmation: Shows you the AI’s message before committing.
Putting It All Together
- Install prerequisites:
brew install jq
# or your distro’s package manager
-
Create a
.env
at your project root:
CODESTRAL_API_KEY=sk-<your-free-key>
- Make the script executable:
chmod +x scripts/ai-git-commit.sh
-
Use it instead of
git commit
:
./scripts/ai-git-commit.sh
Voilà—every commit message now backed by a world‑class open‑source AI model, with none of Copilot’s rate limits or UI hurdles.
Data use and privacy
For details on how Mistral handles user data, see “Do you use my user data to train your Artificial Intelligence models?”
https://help.mistral.ai/en/articles/347617-do-you-use-my-user-data-to-train-your-artificial-intelligence-models
Controls on la Plateforme
- Experiment Plan (Free subscription): As stated during subscription, we may use your data (input and output) to train our artificial intelligence models.
- You have the right to opt out of this program at any time; see: Can I opt-out of my input or output data being used for training? https://help.mistral.ai/en/articles/347614-can-i-opt-out-of-my-input-or-output-data-being-used-for-training
Top comments (0)