A powerful Bash script that intelligently automates Git history cleaning through smart commit squashing and analysis.
Perfect for maintaining clean, conventional commit histories in development workflows.
-
π Smart Commit Analysis: Automatically analyzes commit messages against conventional patterns
-
π Interactive Reporting: Provides detailed reports on commit quality and organization
-
π€ Auto-grouping: Groups commits by type (feat, fix, chore, docs, etc.)
-
π‘οΈ Safety First: Dry-run mode and protected branch checking
-
π― Conventional Commits: Supports and enforces conventional commit standards
-
βοΈ Configurable: Customizable patterns and settings via config file
-
π« Protected Branches: Prevents accidental squashing on main, master, develop branches
curl -L https://github.com/Forz70043/git-smart-squash/blob/master/git-smart-squash.sh -o /usr/local/bin/git-smart-squash
chmod +x /usr/local/bin/git-smart-squash
git clone https://github.com/Forz70043/git-smart-squash.git
cd git-smart-squash
sudo make install # or manually copy to /usr/local/bin/
# Analyze and squash current branch
git-smart-squash
# Specify branch and main branch
git-smart-squash -b feature/xyz -m develop
# Dry run to see what would be done
git-smart-squash --dry-run
# Auto-commit mode with intelligent grouping
git-smart-squash --auto-commit
-b, --branch BRANCH Branch to squash (default: current)
-m, --main MAIN_BRANCH Main branch (default: main)
-n, --dry-run Show what would be done without executing
-c, --config FILE Use custom config file
--auto-commit Automatically create commit messages
--help Show help message
The script automatically creates a configuration file at ~/.git-smart-squash.conf on first run:
# Git Smart Squash Configuration
COMMIT_MSG_PATTERN="^(fix|feat|chore|docs|style|refactor|test|perf):"
MAX_COMMITS_TO_SQUASH=20
EXCLUDE_BRANCHES=("main" "master" "develop")
AUTO_COMMIT_GROUPING=true
Edit the COMMIT_MSG_PATTERN in your config file to match your team's conventions:
# Angular-style commits
COMMIT_MSG_PATTERN="^(fix|feat|chore|docs|style|refactor|test|perf|build|ci|revert):"
# Your custom pattern
COMMIT_MSG_PATTERN="^(BUGFIX|FEATURE|HOTFIX|IMPROVEMENT):"
# 1. Check what needs to be squashed
git-smart-squash --dry-run
# Output:
# π Analyzing commits on 'feature/new-auth' since 'main'...
# π Found 8 commits:
# a1b2c3d feat: add user authentication
# e4f5g6h fix: login form validation
# i7j8k9l WIP: still working on auth
# m1n2o3p chore: update dependencies
# β
Well-formed commits: 3
# β Poor commit messages: 1
# β οΈ Poor commit message: WIP: still working on auth
# 2. Execute the squash
git-smart-squash -b feature/new-auth
# 3. The script will open interactive rebase for you to finalize
# You've been working on a feature with many small commits
$ git log --oneline
d8e7f6c fix: button alignment
c4b3a2f feat: add user profile page
a1b2c3d WIP: profile stuff
f5e4d3c chore: update packages
b2a1c3e docs: update readme
e6d5f4c fix: mobile responsive issues
# Run smart squash
$ git-smart-squash --dry-run
# Output shows organized grouping and suggestions
Add to your ~/.gitconfig:
[alias]
smart-squash = !git-smart-squash
ss = !git-smart-squash --dry-run
# .github/workflows/commit-check.yml
name: Commit Message Check
on: [pull_request]
jobs:
check-commits:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Check commit messages
run: |
git-smart-squash --dry-run --branch ${{ github.head_ref }}
β Not a git repository
Solution: Run the script from within a Git repository.
β Branch 'feature/xyz' does not exist
Solution: Check the branch name or use git branch to see available branches.
β Cannot squash protected branch: main
Solution: The script protects main branches by default. Modify EXCLUDE_BRANCHES in config if needed.
# Enable verbose output
GIT_SMART_SQUASH_DEBUG=1 git-smart-squash -b your-branch
-
Fork the repository
-
Create a feature branch: git checkout -b feature/amazing-feature
-
Commit your changes: git commit -m 'feat: add amazing feature'
-
Push to the branch: git push origin feature/amazing-feature
-
Open a Pull Request
Inspired by conventional commit standards.
Built for developers who value clean Git history.
Thanks to all contributors who help improve this tool.
π§ Email: [email protected]
π Issue Tracker
π¬ Discussions
β Star on GitHub
β Buy me a Coffe