Skip to content
OPQAI.
Sourced intermediate / 💻 Coding Free tools

Auto-Organize Git Commits for PRs with AI

Job to be done: Automatically create organized Git commits for Pull Requests using AI

🇳🇬 Ways to use this in Nigeria

Ideas to get you started, adapt to your situation.

  • 9-5 employee

    For a software developer at a Nigerian tech startup, use AI to re-organize your feature branch commits into clear, digestible chunks, speeding up code reviews from your team lead.

  • Entrepreneur

    As a solo founder building your startup's MVP, automatically organize your code changes into logical commits, making it easier to onboard future developers or debug issues later.

  • Student

    Turn a messy series of commits for your CSC401 group project into a clean, readable history before submitting your final code to your lecturer or project lead.

What you’ll get

A tidy Git history for your branch, where messy work-in-progress commits are reshuffled into a few logical, clearly named commits. Reviewers can then read your changes in small, sensible chunks instead of one giant blob, so your pull requests (PRs, the request to merge your changes into the main code) get reviewed faster. It runs through a free AI model on your own computer, so your code never leaves your machine.

Tools you need

  • Ollama (free): runs an AI language model locally on your computer, so the analysis happens offline with no cloud account or fees.
  • Git (free): the standard tool developers use to track changes to code. You should already have a Git project (a “repository”) with some commits.
  • git-smart-squash (free): the open-source command-line tool by the author that does the actual reorganizing.

Steps

  1. Install Ollama and download a model: get Ollama from its official site (installers for Windows, macOS, and Linux), then pull a model. In your terminal:

    ollama pull llama3

    You should see a download progress bar, then a success message. This model is the local “brain” that will group your changes.

  2. Install git-smart-squash: it is a Python tool, so install it with pip (the standard installer for Python tools). This command is the same on Windows, macOS, and Linux:

    pip install git-smart-squash

    If you have pipx, pipx install git-smart-squash keeps it isolated. Check the project’s GitHub page (github.com/edverma/git-smart-squash) if you hit an install error.

  3. Go to your project folder: in the terminal, move into the Git repository you want to clean up:

    cd path/to/your-project

    Make sure you are on the feature branch you have been working on, not the main branch.

  4. Run the tool: it compares your branch against the base branch (the branch you will merge into, usually main) and asks the local model to group the changes:

    git smart-squash

    You should see it read your changes (“the diff”) and propose a new set of commits with suggested messages. Because the default model is your local Ollama, no extra setup is needed.

  5. Review and accept: read the proposed commits. If they make sense, confirm when prompted. The tool rewrites your history and automatically creates a backup branch first, so your original commits are not lost.

  6. Force-push the cleaned branch: because you rewrote history, a normal push is refused. Use the safer force option, which refuses to overwrite if someone else pushed in the meantime:

    git push --force-with-lease origin your-branch-name

    You should see confirmation that the remote branch now shows your new, tidy commits.

Original source

Based on git-smart-squash, a tool created by edverma2 and shared on Hacker News. It uses AI to reorganize the commits on a branch into clearer, smaller, more logical pieces, with the goal of making pull requests easier and faster to review.

Notes & variations

  • Free-tier viability: completely free. Ollama runs the model locally and Git is free, so there are no API costs and your code stays on your machine.
  • Common pitfall: rewriting history on a branch other people are also working on. Coordinate first, since a force-push changes the shared history. Always confirm the automatic backup branch exists before you push.
  • Tip for better results: try different local models with Ollama (for example a larger one if your computer can handle it). Some understand code context better and write more accurate commit messages than others.

Keep going

More Coding workflows