3 min read
Published on July 15, 2025
Most command-line AI commit message generators require you to use an API key. But I don't have a free API key lying around, so I figured out a way to use the Gemini CLI to generate commit messages. With the Gemini CLI, you can log in using your Google account from the browser.
This might not be the most efficient approach out there, but it works.
Download and authenticate the Gemini CLI. Then, use the following command:
git diff --cached | gemini --prompt "Generate a concise commit message:" | xclip -sel clip && git commit
I've set an alias for this in my ~/.zshrc
:
alias aicommit='git diff --cached | gemini --prompt "Generate a concise commit message:" | xclip -sel clip && git commit'
This basically generates a commit message based on your staged changes, copies it to your clipboard, and opens the Git commit editor (Neovim for me). Then I can paste and modify the commit message from within Neovim.
Note: xclip works on Linux X11. For macOS, replace this with pbcopy.
If there are no staged changes, there's no need to call the Gemini CLI, so I added a check:
aicommit() {
if [ -z "$(git diff --cached)" ]; then
echo "No staged changes to commit."
return 1
fi
git diff --cached | gemini --prompt "Generate a concise commit message:" | xclip -sel clip && git commit
}
Before you source the ~/.zshrc, you might have to unalias the previously set alias.
unalias aicommit 2>/dev/null || true
Now, I wanted a good message to be shown while Gemini is generating the commit, so I improved the function:
aicommit() {
if [ -z "$(git diff --cached)" ]; then
echo "No staged changes to commit."
return 1
fi
echo "🤖 Generating commit message..."
local commit_message=$(git diff --cached | gemini --prompt "Generate a concise commit message:")
if [ $? -eq 0 ] && [ -n "$commit_message" ]; then
echo "✅ Generated commit message: $commit_message"
echo "$commit_message" | xclip -sel clip
git commit
else
echo "❌ Failed to generate commit message."
return 1
fi
}
That's all for now. I might switch to some other workflow, like aicommit2, in the future. But for now, I find this sufficient.
I prefer to write my own commits most of the time, but this is a lifesaver for miscellaneous changes when I don't want to waste time thinking of a message.