How to squash merge in Git
Squash merging combines all commits from a feature branch into a single commit when merging to maintain a clean, linear project history.
As the creator of CoreUI, a widely used open-source UI library, and with over 25 years of experience in software development, I’ve managed thousands of feature merges where clean commit history is crucial for project maintenance.
The most effective approach is using git merge --squash, which combines all changes from the feature branch into staging without creating a merge commit.
This method is perfect for feature branches with multiple work-in-progress commits that should be consolidated.
Use git merge --squash to combine all commits from a feature branch into a single commit for cleaner history.
git checkout main
git merge --squash feature-branch
git commit -m "Add new feature with complete functionality"
The --squash flag takes all changes from the feature branch and stages them as a single set of modifications without committing them. You then create a single commit with a descriptive message that summarizes the entire feature. This approach eliminates intermediate commits like “fix typo” or “work in progress” from the main branch history while preserving all the actual code changes.
Best Practice Note:
This is the approach we use in CoreUI development for feature integration to maintain clean release history. The original feature branch commits remain in the branch history for detailed tracking, while the main branch gets a clean, atomic commit representing the complete feature.



