Skip to main content

Command Palette

Search for a command to run...

Automate your Git Workflow using AI

Published
2 min read
Automate your Git Workflow using AI

Tired of thinking what comments to add for your git commit. This flow will help you.


Prerequisites

  • Git Bash: Installed on your Windows System.

  • Ollama CLI: Installed and configured with phi3.5 model.

  • Basic Knowledge of Git Commands and Terminal Usage.


Step 1: Create the Script File

  1. Open your favorite Text editor and create a new file.

  2. 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!"
    
  3. Save the file as git_auto_commit.sh.


Step 2: Add the Script to Your Global Bin Directory

  1. Create a bin directory if it doesn’t exist:

     mkdir -p ~/bin
    
  2. Move the script to this directory:

mv /path/to/git_auto_commit.sh ~/bin/

Step 3: Make the Script Executable inside a bash terminal.

You can use Git Bash as well to execute it here

chmod +x ~/bin/git_auto_commit.sh

Step 4: Add the Script Directory to Your PATH

  1. Open ~/.bashrc or ~/.bash_profile:

     nano ~/.bashrc
    
  2. Add this line at the end:

     export PATH="$HOME/bin:$PATH"
    
  3. Save and apply changes:

     source ~/.bashrc
    

Step 5: Testing the Script

  1. Navigate to a Git repository.

  2. Run:

     git_auto_commit.sh
    
  3. Follow the prompts.


Additional Notes

  • 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.

GitHub


More from this blog

PageIndex: Vectorless Reasoning-Based RAG Framework

Not all improvements come from adding complexity -- sometimes it's about removing it. PageIndex takes a different approach to RAG. Instead of relying on vector databases or artificial chunking, it builds a hierarchical tree structure from documents and uses reasoning-based tree search to locate most relevant sections. This mirrors how humans approach reading: navigating through sections and context rather than matching embeddings. As a result, the retrieval feels transparent, structured, and explainable. It moves RAG away from approximate semantic vibes and towards explicit reasoning about where information lives.

Mar 10, 20264 min read4
PageIndex: Vectorless Reasoning-Based RAG Framework

Aditya's Blogs

17 posts

Hey there! If you are someone who likes to talk around Tech, I am the one you can talk to anytime. Here I will be sharing my learnings and tech hacks that have personally helped me a lot in my career.