Skip to main content
  1. Learn
  2. Software Development
  3. Guides
  4. Git tutorial
  5. Git basics
  6. Managing Git history
  7. Squashing commits
GuidesSoftware DevelopmentBacklog
Git

Project and code management together.

Squashing commits

Squashing commits in Git involves combining multiple commits into a single commit. This is useful for cleaning up and simplifying the commit history.

Diagram using the squash command.

Use git merge --squash to unify commits from a feature/topic branch into a single commit to be merged into your current branch.

When to use squashing:

  • Before merging: Squash commits before merging a feature branch into the main branch to present the feature as a single, cohesive change.
  • Cleaning up history: Reduce the number of commits in a branch by combining related changes into a single commit, making the history easier to follow.
  • Improving commit messages: Combine multiple commit messages into a more informative and concise message, improving the overall clarity of the commit history.
  • Preparing for review: Present a more coherent set of changes for review by squashing unrelated or minor commits into a single, meaningful commit.

Subscribe to our newsletter

Learn with Nulab to bring your best ideas to life