git-squash

A simple and powerful Git plugin to squash your commits before creating a Pull Request.

This tool provides a unified interface to squash commits:

  • By base branch name (e.g., main, master)
  • By number of recent commits
  • By specific commit SHA

๐Ÿš€ Installation

  1. Download the git-squash script and save it to a directory in your $PATH, e.g.:

    curl -o ~/bin/git-squash https://raw.githubusercontent.com/Ian729/git-squash/main/git-squash
    chmod +x ~/bin/git-squash
    
  2. Ensure the directory is in your $PATH. Add this to your .bashrc / .zshrc if needed:

     export PATH="$HOME/bin:$PATH"
    

Usage

git squash <base-branch>
git squash <number-of-commits>
git squash --sha <commit-sha>

Examples

โœ… Squash all commits made since branching from main:

git squash main

โœ… Squash the last 3 commits:

git squash 3

โœ… Squash all commits made since a specific commit:

git squash --sha <commit-sha>

Note

  • This tool uses git reset โ€“soft, preserving your working directory and staging area.

  • After squashing, use git push โ€“force-with-lease to update the remote branch:

      git push --force-with-lease
    
  • Default commit message is Squashed commit, but you can provide a custom message during the prompt.

๐Ÿ› ๏ธ Why use git-squash?

  • Keep your PR history clean.

  • Avoid git rebase -i complexity in simple squash workflows.

  • Fast, scriptable, and beginner-friendly.

๐Ÿ“„ License

MIT License