Skip to content

Forz70043/git-smart-squash

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Git Smart Squash πŸš€

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.

✨ Features

  • πŸ” 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

πŸ“¦ Installation

Method 1: Direct Download

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

Method 2: Debian Package (Coming Soon)

Method 3: Build from Source

git clone https://github.com/Forz70043/git-smart-squash.git
cd git-smart-squash
sudo make install  # or manually copy to /usr/local/bin/

πŸš€ Usage

Basic Usage

# 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

Command Line Options

Option Description

-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

βš™οΈ Configuration

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

Customizing Commit Patterns

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):"

πŸ“‹ Examples

Example Workflow

# 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

Real-world Scenario

# 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

πŸ› οΈ Integration

With Git Aliases

Add to your ~/.gitconfig:

[alias]
    smart-squash = !git-smart-squash
    ss = !git-smart-squash --dry-run    

With CI/CD Pipelines

# .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 }}

πŸ› Troubleshooting

Common Issues

"Not a git repository"

❌ Not a git repository

Solution: Run the script from within a Git repository.

"Branch does not exist"

❌ Branch 'feature/xyz' does not exist

Solution: Check the branch name or use git branch to see available branches.

"Cannot squash protected branch"

❌ Cannot squash protected branch: main

Solution: The script protects main branches by default. Modify EXCLUDE_BRANCHES in config if needed.

Debug Mode

# Enable verbose output
GIT_SMART_SQUASH_DEBUG=1 git-smart-squash -b your-branch

🀝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

  1. Fork the repository

  2. Create a feature branch: git checkout -b feature/amazing-feature

  3. Commit your changes: git commit -m 'feat: add amazing feature'

  4. Push to the branch: git push origin feature/amazing-feature

  5. Open a Pull Request

πŸ™ Acknowledgments

Inspired by conventional commit standards.
Built for developers who value clean Git history.
Thanks to all contributors who help improve this tool.

πŸ“ž Support

πŸ“§ Email: [email protected]
πŸ› Issue Tracker
πŸ’¬ Discussions

Made with ❀️ for clean Git histories

⭐ Star on GitHub
β˜• Buy me a Coffe

About

Interactive rebase before merge for clean history

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published