Introducing git squash A Simple Git Squashing Tool
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
-
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
-
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