Open In App

Git Squash

Last Updated : 06 Oct, 2025
Comments
Improve
Suggest changes
7 Likes
Like
Report

Git squash takes several commits, especially on feature branches with many small incremental commits, and combines them into one. This prevents clutter and presents a polished, easy-to-follow history to your team.

squashing_commit
Git Squash

Git Squash-Merge Command Line

You can combine commits from a feature branch into a single commit and merge it into your current branch using:

git merge --squash feature-branch

This command condenses all commits from the feature branch into one that is applied onto your current branch. After squash merging, the repository history becomes cleaner and more organized.

How to Squash Commits

There are mainly two way:

1. Interactive Rebase Method

  • Run:
git rebase -i HEAD~3
  • An interactive editor opens listing the last 3 commits.
  • Change pick to squash on commits you want to combine into the first one.
  • Save and close the editor.
  • Another editor opens where you can write a combined commit message.
  • Save and exit to complete rebasing.

After this, your multiple commits will be combined into one.

2. Squashing with the --squash Option

  • Create and switch to your target branch:
git checkout main
  • Merge with squash option:
git merge --squash feature-branch
  • Resolve any merge conflicts manually.
  • Commit combined changes with a message:
git commit -m "Add group video calls and bug fixes"
  • Push changes to the remote repository.

Squashing Last Two Commits

If you want to squash only the last two commits:

  • Switch to your branch.
  • Run:
git rebase -i HEAD~2
  • Change pick to squash for the last commit.
  • Save, update commit message as needed, and close the editor.

Git Squash vs Rebase

Git SquashGit Rebase
You can combine multiple commits into a single commit.Applies commits on top of the different base commits.
After using git squash your commit history will be more clean and organized.You can form a new branch by using previous commits. 
Must be done on private branches. Rebasing can be done on a feature branch or shared branch.
By using squishing you can maintain clean and logical commit history.By using rebase command you can keep your branch up to date.



Article Tags :

Explore