Aditya Trivedi
Apr 17, 2025
Tired of thinking what comments to add for your git commit. This flow will help you.
Git Bash: Installed on your Windows System.
Ollama CLI: Installed and configured with phi3.5
model.
Basic Knowledge of Git Commands and Terminal Usage.
Open your favorite Text editor and create a new file.
Copy and paste the following Bash Script:
#!/bin/bash
# git_auto_commit.sh
if ! git rev-parse --git-dir > /dev/null 2>&1; then
echo "Error: This directory is not a Git repository."
exit 1
fi
if git diff-index --quiet HEAD --; then
echo "No changes detected. Exiting."
exit 0
fi
echo "Staging changes..."
git add .
summary=$(git diff --cached --name-only)
echo "Generating commit message suggestion from Ollama phi3.5..."
suggested_commit_msg=$(ollama run phi3.5 ""Generate a concise yet informative commit message that accurately summarizes the following code changes. The message should be clear, professional, and follow best practices for commit messages. Aim to describe the purpose and impact of the changes in a way that is easy to understand. Avoid unnecessary details but ensure the key modifications are covered. Format the message in an imperative style (e.g., 'Fix bug in authentication flow' instead of 'Fixed a bug...'). Here are the changes to summarize: $summary")
echo "Suggested commit message:"
echo "$suggested_commit_msg"
read -p "Edit commit message? (y/n): " choice
if [[ "$choice" =~ ^[Yy]$ ]]; then
echo "Enter your commit message below. Press Ctrl+D when done."
commit_msg=$(cat) # Reads multiline input until Ctrl+D
else
commit_msg="$suggested_commit_msg"
fi
git commit -m "$commit_msg"
git push origin master
echo "Done!"
Save the file as git_auto_commit.sh
.
Create a bin
directory if it doesnโt exist:
mkdir -p ~/bin
Move the script to this directory:
mv /path/to/git_auto_commit.sh ~/bin/
You can use Git Bash as well to execute it here
chmod +x ~/bin/git_auto_commit.sh
Open ~/.bashrc
or ~/.bash_profile
:
nano ~/.bashrc
Add this line at the end:
export PATH="$HOME/bin:$PATH"
Save and apply changes:
source ~/.bashrc
Navigate to a Git repository.
Run:
git_auto_commit.sh
Follow the prompts.
Ensure Ollama
is installed and running.
Windows NTFS permissions may not reflex Unix-style chmod
changes, but the script will execute.
This script is now available at my GitHub Repository. Go ahead and automate your Git Workflow.